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.
7 comments:
Is there any sample code about compression? I tested it and found the message size is doubled by setting usecompression. Could you help me?
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.
It's really helpful. Thank you!
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 {
private:
int* length;
private:
ByteCounterOutputStream( const ByteCounterOutputStream& );
ByteCounterOutputStream operator= ( const ByteCounterOutputStream& );
public:
ByteCounterOutputStream( int* length, OutputStream* stream, bool own = false )
: FilterOutputStream( stream, own ), length( length ) {
}
virtual ~ByteCounterOutputStream() {}
protected:
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 );
}
};
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.
https://issues.apache.org/jira/browse/AMQCPP
I can get the fix into the next release then.
No problem.
https://issues.apache.org/jira/browse/AMQCPP-371
Post a Comment