我用骆驼(2.11.0)至尝试,实现了以下功能:骆驼文件处理
- 如果文件存在于某一位置,将它复制到另一个位置,然后开始处理它
- 如果没有这样的文件存在,那么我不希望文件消费者/轮询阻止;我只想要继续处理
direct:cleanup
路线
我只希望文件被轮询一次!
这里是我到目前为止(使用Spring XML):
<camelContext id="my-camel-context" xmlns="http://camel.apache.org/schema/spring">
<route id="my-route
<from uri="file:///home/myUser/myApp/fizz?include=buzz_.*txt"/>
<choice>
<when>
<!-- If the body is empty/NULL, then there was no file. Send to cleanup route. -->
<simple>${body} == null</simple>
<to uri="direct:cleanup" />
</when>
<otherwise>
<!-- Otherwise we have a file. Copy it to the parent directory, and then continue processing. -->
<to uri="file:///home/myUser/myApp" />
</otherwise>
</choice>
<!-- We should only get here if a file existed and we've already copied it to the parent directory. -->
<to uri="bean:shouldOnlyGetHereIfFileExists?method=doSomething" />
</route>
<!--
Other routes defined down here, including one with a "direct:cleanup" endpoint.
-->
</camelContext>
通过上述配置,如果在/home/myUser/myApp/fizz
没有文件,那么骆驼只是等待/块,直到有一个。相反,我想让它放弃并转向direct:cleanup
。
如果有一个文件,我看到它在shouldOnlyGetHereIfFileExists
bean中得到处理,但我没有看到它被复制到/home/myUser/myApp
;所以就好像<otherwise>
元素被完全忽略/忽略!
任何想法?提前致谢!
感谢@vikingsteve - 我给你一个+1,但我没有足够的代表。我感觉不好,有一件我忘记提及的重要部分:**我只想要路线轮询文件一次。**你对'sendEmptyMessageWhenIdle'的建议确实有效,但是路线不断轮询,一遍一遍地重现一个文件。关于如何配置Camel只能轮询一次的任何想法?再次感谢! – AdjustingForInflation
那么还有一个'delay'选项 - 你可以尝试将它设置为0或-1,或者一些非常大的值,然后看看会发生什么。否则,在第一次执行路由期间,您可以使用'controlbus'来停止路由。 – vikingsteve
看起来像延迟不能<= 0,但你可以尝试一个非常高的值。否则,抛出异常(你以某种方式处理)也可能会停止路由。 – vikingsteve