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