Zip Deflater
Since Camel 2.12
The Zip Deflater Data Format is a message compression and decompression format. Messages marshaled using Zip compression can be unmarshalled using Zip decompression just prior to being consumed at the endpoint. The compression capability is quite useful when you deal with large XML and Text based payloads. It facilitates more optimal use of network bandwidth while incurring a small cost to compress and decompress payloads at the endpoint.
| This dataformat is not for working with zip files such as uncompressing and building zip files. Instead, use the zipfile dataformat. |
Message Body
The message body at each side of the Zip Deflater data format: Marshal input and Unmarshal input are the bodies marshal and unmarshal can take, and Marshal output and Unmarshal output the body after them.
| Side | Body | Description |
|---|---|---|
Marshal input |
| The data to compress: text in the charset of the exchange, bytes, a stream or a file. |
Marshal output |
| The deflate data in the zlib format, not a zip file, in the stream cache, or a byte array when stream caching is off. |
Unmarshal input |
| Deflate data in the zlib format, such as marshal gives with any compressionLevel. |
Unmarshal output |
| The decompressed data in the stream cache, or a byte array when stream caching is off. |
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers are described in the Camel Catalog.
Marshal
In this example we marshal a regular text/XML payload to a compressed payload employing zip compression Deflater.BEST_COMPRESSION and send it an ActiveMQ queue called MY_QUEUE.
from("direct:start").marshal().zipDeflater(Deflater.BEST_COMPRESSION).to("activemq:queue:MY_QUEUE"); Alternatively, if you would like to use the default setting, you could send it as
-
Java
-
XML
-
YAML
from("direct:start").marshal().zipDeflater().to("activemq:queue:MY_QUEUE"); <route>
<from uri="direct:start"/>
<marshal><zipDeflater/></marshal>
<to uri="activemq:queue:MY_QUEUE"/>
</route> - route:
from:
uri: direct:start
steps:
- marshal:
zipDeflater: {}
- to:
uri: activemq:queue:MY_QUEUE Unmarshal
In this example, we unmarshal a zipped payload from an ActiveMQ queue called MY_QUEUE to its original format, and forward it for processing to the UnZippedMessageProcessor. Unmarshal reads the data of any compression level, so the level of the marshal does not need to be set.
from("activemq:queue:MY_QUEUE").unmarshal().zipDeflater().process(new UnZippedMessageProcessor()); Dependencies
If you use Maven you could add the following to your pom.xml, substituting the version number for the latest and greatest release (see the download page for the latest versions).
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-zip-deflater</artifactId>
<version>x.x.x</version>
</dependency>