Apache camel Camel:处理文件、拆分和聚合
我手头有一个情况,我需要从目录中读取并处理那里的所有XML文件。然后根据某些规则处理和拆分文件,从而生成N条新消息/文件。我想将所有新文档聚合到一个索引文件中,每个文件一行。一旦批处理完成,我将调用一个webservice并告诉它获取索引文件 我面临的问题是,Camel没有将文件的交付视为一个作业,并且我的聚合被多次调用,导致多个索引文件而不是一个。我已尝试使用Apache camel Camel:处理文件、拆分和聚合,apache-camel,Apache Camel,我手头有一个情况,我需要从目录中读取并处理那里的所有XML文件。然后根据某些规则处理和拆分文件,从而生成N条新消息/文件。我想将所有新文档聚合到一个索引文件中,每个文件一行。一旦批处理完成,我将调用一个webservice并告诉它获取索引文件 我面临的问题是,Camel没有将文件的交付视为一个作业,并且我的聚合被多次调用,导致多个索引文件而不是一个。我已尝试使用Exchange.BATCH\u SIZE属性并将其乘以Exchange.SPLIT\u SIZE进行聚合completionSize
Exchange.BATCH\u SIZE
属性并将其乘以Exchange.SPLIT\u SIZE
进行聚合completionSize
伪代码:
from("file://" + SOURCE_FOLDER)
.threads(10)
.convertBodyTo(Data.class)
.process(myProcessor)
.split(xpath(MAIN_NODE))
.parallelProcessing()
.to(MyRouter.ENDPOINT)
.setProperty(TOTAL)
.spel(String.format("%s * %s", Exchange.SPLIT_SIZE, FileRouter.NUM_FILES))
.aggregate(constant(true), myAggregator)
....
所以问题是:我如何定义exchange/group it的边界?我知道一次只能传送一个文件,但我怎么能告诉骆驼呢
我试着只使用一个线程,但在我看来,它对这个问题没有任何影响
我可以选择以tar.gz的形式交货,这样会更容易吗?对我来说,似乎我也有同样的问题
from("file://" + SOURCE_FOLDER + "/tar.gz?consumer.delay=1000&noop=true")
.streamCaching()
.unmarshal()
.gzip()
.split(new TarSplitter())
....<SAME ISSUE>
from(“文件:/”+源文件夹+“/tar.gz?consumer.delay=1000&noop=true”)
.streamCaching()
.unmarshal()
.gzip()
.split(新的TarSplitter())
....
我正在使用骆驼3预览版,尽管我也尝试过最新的2.x版本
请提前向我表示感谢,当我正确理解您时,您的问题是无法为每个输入文件创建聚合索引 嗯,Camel可以与组合使用
// a Splitter with an AggregationStrategy
.split([yourSplitCriteria], new MyAggregationStrategy())
// you can do whatever you want in here with the message parts
// for example each splitted message part is sent to this bean
.to("bean:PartProcessor")
// end the split to re-aggregate the message parts
.end()
// here, after the split-ending you get the re-aggregated messages
如果执行此操作,拆分器将以前拆分的邮件的所有部分重新聚合为新的聚合
// a Splitter with an AggregationStrategy
.split([yourSplitCriteria], new MyAggregationStrategy())
// you can do whatever you want in here with the message parts
// for example each splitted message part is sent to this bean
.to("bean:PartProcessor")
// end the split to re-aggregate the message parts
.end()
// here, after the split-ending you get the re-aggregated messages
谢谢你的帮助,但这并不能解决我的问题。通过使用tar文件传递和使用处理器收集自己的数据,我以不同的方式解决了这个问题。现在它起作用了。