This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Zip File DataFormat
Skip to end of metadata
Go to start of metadata

Zip File

Available since Camel 2.11.0


The Zip File Data Format is a message compression and de-compression format. Messages can be marshalled (compressed) to Zip files containing a single entry, and Zip files containing a single entry can be unmarshalled (decompressed) to the original file contents. This data format supports ZIP64, as long as Java 7 or later is being used.

Since Camel 2.12.3 there is also a aggregation strategy that can aggregate multiple messages into a single Zip file.


In this example we marshal a regular text/XML payload to a compressed payload using Zip file compression, and send it to an ActiveMQ queue called MY_QUEUE.


The name of the Zip entry inside the created Zip file is based on the incoming CamelFileName message header, which is the standard message header used by the file component. Additionally, the outgoing CamelFileName message header is automatically set to the value of the incoming CamelFileName message header, with the ".zip" suffix. So for example, if the following route finds a file named "test.txt" in the input directory, the output will be a Zip file named "" containing a single Zip entry named "test.txt":


If there is no incoming CamelFileName message header (for example, if the file component is not the consumer), then the message ID is used by default, and since the message ID is normally a unique generated ID, you will end up with filenames like If you want to override this behavior, then you can set the value of the CamelFileName header explicitly in your route:

from("direct:start").setHeader(Exchange.FILE_NAME, constant("report.txt")).marshal().zipFile().to("file:output/directory");

This route would result in a Zip file named "" in the output directory, containing a single Zip entry named "report.txt".


In this example we unmarshal a Zip file payload from an ActiveMQ queue called MY_QUEUE to its original format, and forward it for processing to the UnZippedMessageProcessor.

from("activemq:queue:MY_QUEUE").unmarshal().zipFile().process(new UnZippedMessageProcessor()); 

If the zip file has more then one entry, the usingIterator option of ZipFileDataFormat to be true, and you can use splitter to do the further work.

  ZipFileDataFormat zipFile = new ZipFileDataFormat();
          .process(new UnZippedMessageProcessor())

Or you can use the ZipSplitter as an expression for splitter directly like this

     .split(new ZipSplitter())
        .process(new UnZippedMessageProcessor())


Available since Camel 2.12.3


Please note that this aggregation strategy requires eager completion check to work properly.


In this example we aggregate all text files found in the input directory into a single Zip file that is stored in the output directory. 

     .aggregate(new ZipAggregationStrategy())


The outgoing CamelFileName message header is created using, with the ".zip" suffix. If you want to override this behavior, then you can set the value of the CamelFileName header explicitly in your route:


     .aggregate(new ZipAggregationStrategy())
     .setHeader(Exchange.FILE_NAME, constant(""))



To use Zip files in your camel routes you need to add a dependency on camel-zipfile which implements this data format.

If you use Maven you can just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions).

  <!-- use the same version as your Camel core version -->
  • No labels