JMSCorrelationID

In the B2B example, we are using the JMSCorrelationID as a way for the Retailer to associate its identity with its reply message, as illustrated by the following code in Retailer.autoBuy( ) :

private void autoBuy (javax.jms.Message message){
    ...
    publisher = session.createPublisher(buytopic);
    textMsg.setJMSCorrelationID("DurableRetailer");
                
    publisher.publish(
           textMsg,
           javax.jms.DeliveryMode.PERSISTENT,
           javax.jms.Message.DEFAULT_PRIORITY,
           1800000);
        ...           
}

In Wholesaler, the JMSCorrelationID is extracted in the onMessage( ) handler, and simply printed on the command line:

public void onMessage( javax.jms.Message message){
        ...           
         System.out.println("Order received - "+text+
                            " from " + message.getJMSCorrelationID( ));
        ...           
   }

Another way to associate the Retailer's identity with the reply message would be to store something unique in a message property, or in the message body itself.

A more common use of the JMSCorrelationID is not for the sake of establishing identity; it is for correlating the asynchronous reception of a message with a message that had been previously sent. A message consumer wishing to create a message to be used as a response may place the JMSMessageID of the original message in the JMSCorrelationID of the response message.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset