68.3. Unmarshal
この例では、MY_QUEUE という ActiveMQ キューから Zip ファイルペイロードを元の形式にアンマーシャリングして UnZippedMessageProcessor
に転送し、処理します。
from("activemq:queue:MY_QUEUE") .unmarshal().zipFile() .process(new UnZippedMessageProcessor());
from("activemq:queue:MY_QUEUE")
.unmarshal().zipFile()
.process(new UnZippedMessageProcessor());
zip ファイルに複数のエントリーがある場合には、ZipFileDataFormat の usingIterator オプションを true にすると、スプリッターを使用してさらに作業を行うことができます。
または、このように ZipSplitter をスプリッターの式として直接使用できます
from("file:src/test/resources/org/apache/camel/dataformat/zipfile?delay=1000&noop=true") .split(new ZipSplitter()).streaming() .process(new UnZippedMessageProcessor()) .end();
from("file:src/test/resources/org/apache/camel/dataformat/zipfile?delay=1000&noop=true")
.split(new ZipSplitter()).streaming()
.process(new UnZippedMessageProcessor())
.end();
68.3.1. Aggregate リンクのコピーリンクがクリップボードにコピーされました!
この集約ストラテジーでは、正しく機能させるには、先行して完了チェックを行う必要があります。
この例では、入力ディレクトリーで見つかったすべてのテキストファイルを、出力ディレクトリーに格納される 1 つの 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");