Thursday, March 11, 2010

ActiveMQ-CPP now supports Message body compression

If you download the latest source from SVN you will find that you can now set the useCompression option on the Connection URI and your Message bodies will be compressed using a Java compatible ZLib deflater. This allows you to reduce larger payloads for faster transmission on the wire and should be fully compatible with the AMQ Java client and with the NMS.ActiveMQ client if you use the DotNetZip library in a compression policy, more about that later.


無尾熊可愛 said...
This comment has been removed by a blog administrator.
markqiu said...

Is there any sample code about compression? I tested it and found the message size is doubled by setting usecompression. Could you help me?

Tim said...

There's really not much at all to it, you simply add the URI option connection.useCompression=true to your client's URI and that's it. Its entirely possible given the right payload for zlib compression to double the size of the message body, using it for small messages is not recommended.

markqiu said...

It's really helpful. Thank you!

markqiu said...

Hi, Tim.
It seems I catched the bug.
If the URI option connection.useCompression=true, an ActiveMQBytesMessage will always become double sized. I changed the ActiveMQByteMessage.cpp as follow, the problem seems solved. Please help me!

class ByteCounterOutputStream : public FilterOutputStream {

int* length;


ByteCounterOutputStream( const ByteCounterOutputStream& );
ByteCounterOutputStream operator= ( const ByteCounterOutputStream& );


ByteCounterOutputStream( int* length, OutputStream* stream, bool own = false )
: FilterOutputStream( stream, own ), length( length ) {

virtual ~ByteCounterOutputStream() {}


virtual void doWriteByte( unsigned char value ) {
//(*length)++; removed because of length has been double sized
FilterOutputStream::doWriteByte( value );

virtual void doWriteArray( const unsigned char* buffer, int size ) {

(*length) += size;
FilterOutputStream::doWriteArray( buffer, size );

virtual void doWriteArrayBounded( const unsigned char* buffer, int size, int offset, int length ) {

(*this->length) += length;
FilterOutputStream::doWriteArrayBounded( buffer, size, offset, length );


Tim said...

It'd be great if you could create a new Jira issue for this problem and attach your fixes as a patch, granting license to apache of course.

I can get the fix into the next release then.

markqiu said...

No problem.