简体   繁体   English

如何使用Apache Camel仅加载单个文件?

[英]How to use Apache Camel to load just a single file?

Apache Camel has a very nice support for various protocols like FTP and "file" and I would like to use it just to just load a single file and maybe convert it a bit. Apache Camel对FTP和“文件”等各种协议都有很好的支持,我想使用它只是加载单个文件并进行一些转换。

I understood how to do this using a RouteBuilder and CamelContext.start() like in the examples but I don't want a background daemon in an endless loop nor do I need complex routing. 我理解了如何像示例中一样使用RouteBuilder和CamelContext.start()来做到这一点,但我不想在无尽循环中使用后台守护程序,也不需要复杂的路由。

How can I do something like: 我该怎么做:

String body = new DefaultCamelContext().justRunOnce(
   from("ftp://ftp.example.com/data/foo.txt")
     .validate(body().regex("My Data.*"))
     .getBody());

I did read some answers on how to stop a Route using "controlbus?action=stop" or "timer?repeat=1" or similar but those still start Camel as a new thread and then use some hack to stop it. 我确实读过一些有关如何使用“ controlbus?action = stop”或“ timer?repeat = 1”或类似的方法停止路由的答案,但是那些仍然将Camel作为新线程启动,然后使用一些技巧将其停止。 I'm not looking for a complicated solution that somehow manages it but rather would like to know if Camel is capable to be used in a lean 10-liner, like in my example above. 我不是在寻找某种可以通过某种方式来管理它的复杂解决方案,而是想知道Camel是否能够像在上面的示例中那样用在薄的10衬套中。

You can use the pollEnricht feature, see http://camel.apache.org/content-enricher.html : 您可以使用pollEnricht功能,请参阅http://camel.apache.org/content-enricher.html

Example, you can also use a ftp endpoint instead of a file endpoint: 例如,您还可以使用ftp端点而不是文件端点:

<route>
 <from uri="direct:start"/>
  <pollEnrich>
   <constant>file:inbox?fileName=data.txt</constant>
  </pollEnrich>
<to uri="direct:result"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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