Red Hat Training

A Red Hat training course is available for Red Hat Fuse

355.4. Aggregate

注記

この集約ストラテジーを適切に機能させるには、完了の先行チェックが必要であることに注意してください。

この例では、入力ディレクトリーで見つかったすべてのテキストファイルを、出力ディレクトリーに格納される 1 つの Zip ファイルに集約します。 

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");