骆驼:拆分收集和写入文件 [英] Camel: Splitting a collection and writing to files
问题描述
我正尝试拆分一个ArrayList和写作每个元素在汇入作业本简单的例子使用Apache的骆驼像自己的文件:
I´m trying to split an ArrayList and writing each element to it´s own file using Apache Camel like in this simplified example:
from("timer://poll?period=10000").process(new Processor(){
public void process(Exchange exchange){
ArrayList<String> list = new ArrayList<String>();
list.add("one");
list.add("two");
list.add("three");
exchange.getIn().setBody(list, ArrayList.class);
}
}).split(body()).log(body().toString()).to("file:some/dir");
日志打印每一个项目,但只有三国被保存到一个文件中。我在做什么错了?
The log prints each item but only "three" is saved to a file. What am I doing wrong?
月
推荐答案
文件生产者将默认为覆盖,如果文件已经存在。
The file producer will by default "override" if a file already exists.
查看fileExist选择在其文档页面
http://camel.apache.org/file2
See the fileExist option at its documentation page http://camel.apache.org/file2
由于输入到该路由也是一个文件,则生产者将来自输入继承的文件名。
Since the input to this route is also a file, then the producer will "inherit" the file name from the input.
所以你的情况,如果你想保存每个分裂的消息在一个新的文件,那么你就需要设置一个目标文件名,使用文件名选项
So in your case if you want to save each splitted message in a new file, then you would need to set a target file name, using the fileName option
"file:some/dir?fileName=splitted-${id}"
filename选项支持简单和文件的语言
The fileName option supports the simple and file language
http://camel.apache.org/simple.html
http://camel.apache.org/file-language.html
这意味着该文件名可以是动态的计算,如上述,其中$ {ID}是一个唯一的消息ID。
That means the file name can be dynamic computed, such as above, where ${id} is an unique message id.
这篇关于骆驼:拆分收集和写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!