【发布时间】:2014-02-11 01:23:24
【问题描述】:
我正在使用 Camel (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 处没有文件,那么 Camel 只会等待/阻塞,直到有文件为止。相反,我希望它放弃并转到direct:cleanup。
如果有文件,我看到它在 shouldOnlyGetHereIfFileExists bean 中得到处理,但我没有看到它被复制到 /home/myUser/myApp;所以几乎就好像 <otherwise> 元素被完全跳过/忽略了!
有什么想法吗?提前致谢!
【问题讨论】:
标签: java configuration routing apache-camel file-uri