384.5. 聚合
注意
请注意,此聚合策略需要 eager 完成检查才能正常工作。
在本例中,我们将输入目录中找到的所有文本文件聚合到一个 Zip 文件中,该文件存储在输出目录中。
from("file:input/directory?antInclude=*/.txt")
.aggregate(constant(true), new ZipAggregationStrategy())
.completionFromBatchConsumer().eagerCheckCompletion()
.to("file:output/directory");
from("file:input/directory?antInclude=*/.txt")
.aggregate(constant(true), new ZipAggregationStrategy())
.completionFromBatchConsumer().eagerCheckCompletion()
.to("file:output/directory");
传出的 CamelFileName 消息标头使用 java.io.File.createTempFile (带有 ".zip" 后缀)创建。如果要覆盖此行为,您可以在路由中明确设置 CamelFileName 标头的值:
from("file:input/directory?antInclude=*/.txt")
.aggregate(constant(true), new ZipAggregationStrategy())
.completionFromBatchConsumer().eagerCheckCompletion()
.setHeader(Exchange.FILE_NAME, constant("reports.zip"))
.to("file:output/directory");
from("file:input/directory?antInclude=*/.txt")
.aggregate(constant(true), new ZipAggregationStrategy())
.completionFromBatchConsumer().eagerCheckCompletion()
.setHeader(Exchange.FILE_NAME, constant("reports.zip"))
.to("file:output/directory");