O'Reilly - Java Message Service
O'Reilly - Java Message Service
O'Reilly - Java Message Service
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
The JMSDeliveryMode can be obtained from the <strong>Message</strong> object using the<br />
getJMSDeliveryMode( ) method:<br />
public void on<strong>Message</strong>(<strong>Message</strong> message){<br />
try {<br />
if (message.getJMSDeliveryMode( ) == DeliveryMode.PERSISTENT){<br />
// Do something<br />
} else {<br />
// Do something else<br />
}<br />
} catch (JMSException jmse){jmse.printStackTrace( );}<br />
}<br />
JMS<strong>Message</strong>ID Purpose: Routing<br />
The JMS<strong>Message</strong>ID is a String value that uniquely identifies a message. How unique the<br />
identifier is depends on the vendor. It may only be unique for that installation of the<br />
message server, or it may be universally unique.<br />
The JMS<strong>Message</strong>ID can be useful for historical repositories in applications where messages<br />
need to be uniquely indexed. The JMS<strong>Message</strong>ID is also useful for correlating messages,<br />
which is done using the JMSCorrelationID header.<br />
The message provider generates the JMS<strong>Message</strong>ID automatically when the message is<br />
received from a JMS client. The JMS<strong>Message</strong>ID must start with ID:, but the rest of<br />
JMS<strong>Message</strong>ID can be any collection of characters that uniquely identifies the message to<br />
the JMS provider. Here is an example of a JMS<strong>Message</strong>ID generated by Progress' SonicMQ:<br />
// JMS<strong>Message</strong>ID generated by SonicMQ<br />
ID:6c867f96:20001:DF59525514<br />
If a unique message ID is not needed by the JMS application, the JMS client can provide a<br />
hint to the message server that an ID is not necessary by using the setDisable<strong>Message</strong>ID( )<br />
method (as shown in the following code). Vendors that heed this hint can reduce message<br />
processing time by not generating unique IDs for each message. If a JMS<strong>Message</strong>ID is not<br />
generated, the getJMS<strong>Message</strong>ID( ) method returns null:<br />
// Publish-and-subscribe<br />
TopicPublisher topicPublisher = topicSession.createPublisher(topic);<br />
topicPublisher.setDisable<strong>Message</strong>ID(true);<br />
// Point-to-point<br />
QueueSender queueSender = queueSession.createSender(topic);<br />
queueSender.setDisable<strong>Message</strong>ID(true);<br />
159