Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Advanced JMS Messaging with OpenJMS

Learn to use the more advanced features of OpenJMS to filter messages, create clients that can receive messages sent even when they aren't running, and create persistent messages that can survive a provider failure.


advertisement
n a previous article I covered some of the basics of JMS using OpenJMS as the JMS provider. In this article, you'll see some more advanced OpenJMS topics such as message selectors, durable subscriptions, and message persistence along with code examples that show you how to implement these concepts programmatically.

Message Selectors
Sometimes you don't want message consumers to receive every message sent by a sender or publisher. Instead you want to be able to filter received messages. The JMS API provides this facility through message selectors. The message consumer specifies which messages it is interested in. The JMS provider then selectively sends just those messages to the client. Note that the onus of filtering messages is left up to the JMS provider, not the consuming application. The provider can scrutinize the header values and message properties with message selectors, but unfortunately, OpenJMS cannot analyze the incoming message bodies. I'll show you an example message selector in just a bit, but first here are a couple of topics (no JMS pun intended) to set the stage.

Message Header Fields
When a JMS provider sends a message it generates the following header fields:

  • JMSMessageID—A unique message identifier
  • JMSDestination—The queue or topic to which the message is sent.
  • JMSRedelivered—States whether the message has been resent
The client sending application can set a number of header fields. Refer to the JMS API documentation for a full breakdown of what headers the client can set. Each header field has getter and setter methods. Some of the fields the client can set include:

  • JMSPriority—You can set a message priority from 0 to 9 (9 being the highest priority and 4 being the default). However, note that the there is no guarantee that higher priority messages will be delivered before lower priority ones.
  • JMSType—String identifying contents of a message
  • JMSReplyTo—Where responses should be sent
  • JMSExpiration—An expiration time for the message
Message Properties
While the preceding message header fields are predefined, clients can add more information to JMS messages via the extensibility of properties. These properties are name/value pairs which the client application defines. The values for properties can be of type boolean, byte, short, int, long, float, double, or string (each type has a corresponding Message.setProperty method). For example, using the syntax below, you could set a property named "Sport" to "Basketball"



Message.setStringProperty("Sport","Basketball");




Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap