Java 源文件夹为空时停止骆驼路由(文件传输)

Java 源文件夹为空时停止骆驼路由(文件传输),java,apache-camel,spring-dsl,Java,Apache Camel,Spring Dsl,我正在尝试创建一个简单的camel应用程序,用于将文件从一个文件夹传输到另一个文件夹 我想问两个问题 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 p

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

我想问两个问题

 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,我尝试了(基于)

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

谢谢,
Kallada

要在春季DSL中停止骆驼路线,只需在“其他”部分中添加。文件中应包含SendEmptyMessageWhenId选项:in@ltsallas对不起,我没有意识到这个错误!非常感谢。是否有方法将路由配置为等待至少一条实际消息通过路由?也许之后?您想关闭路线的具体原因是什么?
    <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>
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();
    }
}