gpt4 book ai didi

java - 一旦源文件夹为空,停止 Camel 路由(文件传输)

转载 作者:太空宇宙 更新时间:2023-11-04 06:23:04 25 4
gpt4 key购买 nike

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

File Transfer Camel Flow

我有两个问题

 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,我尝试了一些类似的东西(基于 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>

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 处理器似乎也不会被调用。任何指示都会对我们有很大帮助。

谢谢,卡拉达

最佳答案

要在 Spring DSL 中停止 Camel 路由,只需在“Others”部分中添加 即可。

关于java - 一旦源文件夹为空,停止 Camel 路由(文件传输),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27190724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com