簡體   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