Skip to Main Content
Java Message Service
book

Java Message Service

by David A Chappell, Richard Monson-Haefel
December 2000
Intermediate to advanced content levelIntermediate to advanced
240 pages
6h 9m
English
O'Reilly Media, Inc.
Content preview from Java Message Service

Name

JMSCorrelationID — Purpose: Routing

Synopsis

The JMSCorrelationID provides a header for associating the current message with some previous message or application-specific ID. In most cases, the JMSCorrelationID will be used to tag a message as a reply to a previous message. The following code shows how the JMSCorrelationID is set and used along with the JMSReplyTo and JMSMessageID headers to send a reply to a message:

public void onMessage(Message message){
    try {
        TextMessage textMessage = (TextMessage)message;
        Topic replyTopic = (Topic)textMessage.getJMSReplyTo(  );
        Message replyMessage = session.createMessage(  );
        String messageID = textMessage.getJMSMessageID(  );
        replyMessage.setJMSCorrelationID(messageID);
        publisher.publish(replyTopic, replyMessage);
    } catch (JMSException jmse){jmse.printStackTrace(  );}
}

When the JMS client receives the reply message, it can match the JMSCorrelationID of the new message with the corresponding JMSMessageID of the message it sent, so that it knows which message received a reply. The JMSCorrelationID can be any value, not just a JMSMessageID. The JMSCorrelationID header is often used with application-specific identifiers. Our example in Chapter 4 uses the JMSCorrelationID as a way of identifying the sender. The important thing to remember, however, is that the JMSCorrelationID does not have to be a JMSMessageID, although it frequently is. If you decide to use your own ID, be aware that an application-specific JMSCorrelationID must not start with ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Spring Boot 2.0

Mastering Spring Boot 2.0

Dinesh Rajput
Cloud Native Java

Cloud Native Java

Josh Long, Kenny Bastani

Publisher Resources

ISBN: 0596000685Supplemental ContentErrata Page