23.07.2013 Views

O'Reilly - Java Message Service

O'Reilly - Java Message Service

O'Reilly - Java Message Service

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3.1.1.3 JMS<strong>Message</strong>ID<br />

<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><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. The JMS<strong>Message</strong>ID can be useful for historical<br />

repositories in JMS consumer applications where messages need to be uniquely indexed.<br />

Used in conjunction with the JMSCorrelationID, the JMS<strong>Message</strong>ID is also useful for<br />

correlating messages:<br />

String messageid = message.getJMS<strong>Message</strong>ID( );<br />

3.1.1.4 JMSTimestamp<br />

The JMSTimestamp is set automatically by the message producer when the send( )<br />

operation is invoked. The timestamp is a long value that measures time in milliseconds:<br />

long timestamp = message.getJMSTimestamp( );<br />

3.1.1.5 JMSExpiration<br />

A <strong>Message</strong> object's expiration date prevents the message from being delivered to<br />

consumers after it has expired. This is useful for messages whose data is only valid for a<br />

period of time:<br />

long timeToLive = message.getJMSExpiration( );<br />

The expiration time for messages is set in milliseconds on the producer (i.e.,<br />

TopicPublisher) using the setTimeToLive( ) method:<br />

TopicPublisher topicPublisher = topicSession.createPublisher(topic);<br />

// Set time to live as 1 hour (1000 millis x 60 sec x 60 min)<br />

topicPublisher.setTimeToLive(3600000);<br />

By default the timeToLive is zero (0), which indicates that the message doesn't expire.<br />

Calling setTimeToLive( ) with a zero argument ensures that a message is created without<br />

an expiration date.<br />

3.1.1.6 JMSRedelivered<br />

The JMSRedelivered header indicates that the message was redelivered to the consumer.<br />

The JMSRedelivered header is true if the message is redelivered, and false if it's not. A<br />

message may be marked redelivered if a consumer failed to acknowledge previous delivery<br />

of the message, or when the JMS provider is not certain whether the consumer has already<br />

received the message:<br />

boolean isRedelivered = message.getJMSRedelivered( )<br />

<strong>Message</strong> redelivery is covered in more detail in Chapter 6.<br />

3.1.1.7 JMSPriority<br />

The message producer may assign a priority to a message when it is delivered. There are<br />

two categories of message priorities: levels 0-4 are gradations of normal priority; levels 5-<br />

36

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!