Broker 10.15 | webMethods Broker Documentation | webMethods Broker Messaging Programmer's Guide | Message Compression | Enabling Message Compression | Compressing a Single Message
 
Compressing a Single Message
To enable message compression on a per-message basis, the following methods are provided. Note that in the interface code, the compression ratio for a sent message is calculated as follows:
ratio = ((uncompressed - compressed)/uncompressed) * 100
*For JMS messaging:
public interface WmMessage {
 
// Enables or disables compression for this message.
public void setCompression(boolean compress);
 
// Get the value for whether compression is enabled or disabled.
public void getCompression();
 
// Get the compression ratio for message that was sent.
public int getCompressionRatio();
}
The following example shows how to compress a single message for JMS.
// Create a topic publisher.
TopicPublisher pub = session.createPublisher(topic);
 
// Create a text message.
TextMessage msg = session.createTextMessage(text);
 
// Set the compression.
msg.setCompression(true);
 
// Publish the message.
pub.publish(msg);
 
// Print the compression ratio.
int ratio = ((WmMessage) msg).getCompressionRatio();
System.out.println("compression ratio = " + ratio);
*For C# messaging:
Boolean Compression () }
{
set;
get;
}
int CompressionRatio
{
get;
}
}
The following example shows how to compress a single message for C#.
// Create a topic publisher.
IMessageProducer pub = session.createPublisher(topic);
 
// Create a text message.
ITextMessage msg = session.createTextMessage(text);
 
// Set the compression.
msg.Compression = true;
 
// Publish the message.
pub.publish(msg);
 
// Print the compression ratio.
int ratio = msg.CompressionRatio;
System.out.println("compression ratio = " + ratio);