136.4. 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 的 useIterator 选项为 true,您可以使用 splitter 来进一步工作。
或者您可以使用 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();
136.4.1. Aggregate 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
注意
此聚合策略需要 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");