1

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

文件传输骆驼流

我有两个问题

 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();
    }
}

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

谢谢,卡拉达

4

1 回答 1

1

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

于 2014-12-04T14:34:41.533 回答