简体   繁体   中英

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

I'm trying to create a simple camel application for transferring files from one folder to another.

文件传输骆驼流

I have two questions in mind

 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.

For, 1, I tried some thing like ( based on camel stop when there are no files in the folder 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>

The shutDownProcessor processor looks something like,

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

But it seems the shutDownProcessor processor is not being invoked even if the source folder is empty. Any pointers will help us a lot.

Thanks, Kallada

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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