Sun GlassFish Message Queue 4.4 Developer's Guide for Java Clients

Compression Examples

Example 3–1 shows how you set and send a compressed message:


Example 3–1 Sending a Compressed Message


//topicSession and myTopic are assumed to have been created
topicPublisher publisher = topicSession.createPublisher(myTopic);
BytesMessage bytesMessage=topicSession.createBytesMessage();

//byteArray is assumed to have been created
bytesMessage.writeBytes(byteArray);

//instruct the client runtime to compress this message
bytesMessage.setBooleanProperty("JMS_SUN_COMPRESS", true);

//publish message to the myTopic destination
publisher.publish(bytesMessage);

Example 3–2 shows how you examine compressed and uncompressed message body size. The bytesMessage was created as in Example 3–1:


Example 3–2 Comparing Compressed and Uncompressed Message Size


//get uncompressed body size
int uncompressed=bytesMessage.getIntProperty(“JMS_SUN_UNCOMPRESSED_SIZE”);

//get compressed body size
int compressed=bytesMessage.getIntProperty(“JMS_SUN_COMPRESSED_SIZE”);