繁体   English   中英

源文件夹为空后停止骆驼路线(文件传输)

[英]Stop camel route(File transfer) once the source folder is empty

我正在尝试创建一个简单的骆驼应用程序,用于将文件从一个文件夹传输到另一个文件夹。

文件传输骆驼流

我有两个问题

 1. Is there a way to stop the route once the source folder is empty.
 2. Is there a way to signel camel to stop the process, but in this case the camel should wait till the in-flight messages are processed.

对于1,我尝试了类似的操作((基于骆驼停止功能,当文件夹 http://camel.apache.org/how-can-i-stop-a-route-from-a-route 中没有文件时) 。 html

    <bean id="shutDownProcessor" class="com.acme.framework.util.ShutDownProcessor" />
    <route customId="true" id="ftpSend">
            <from uri="file:in"/>
            <choice>
                <when>
                    <simple>${body} != null</simple>
                    <wireTap uri="file:copy?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}-${file:size}.${file:ext}&amp;sendEmptyMessageWhenIdle=true">
                        <setHeader headerName="fileName">
                            <simple>${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}-${file:size}.${file:ext}</simple>
                        </setHeader>
                    </wireTap>
                    <to uri="file:out"/>
                </when>
                <otherwise>
                    <process ref="shutDownProcessor"/>
                </otherwise>
            </choice>
        </route>

shutDownProcessor处理器看起来像这样,

public class ShutDownProcessor implements Processor{
    Thread stop;

    @Override
    public void process(final Exchange exchange) throws Exception {
        if (stop == null) {
            stop = new Thread() {
                @Override
                public void run() {
                    try {
                        CamelContext context = exchange.getContext();
                        String currentRoute = context.getRoutes().get(0).getId();
                        context.stopRoute(currentRoute);
                        context.stop();
                    } catch (Exception e) {
                        // ignore
                    }
                }
            };
        }
        stop.start();
    }
}

但是,即使源文件夹为空,似乎shutdownDownProcessor处理器也没有被调用。 任何指针都会对我们有很大帮助。

谢谢,卡拉达

要在Spring DSL中停止骆驼路线,只需在else部分中添加<camel:stop> </ camel:stop>即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM