Suresh Rohan's Blog

This blog is all about Java, J2EE,Spring, Angular, React JS, NoSQL, Microservices, DevOps, BigData, Tutorials, Tips, Best practice, Interview questions, Views, News, Articles, Techniques, Code Samples, Reference Application and much more

Thursday, October 15, 2015

Pattern: Return Address

Pattern: Return Address


  • Each consumer has its own reply queue
  • How does the provider know where to send the reply?
    • Could send to all consumers -> very inefficient
    • Hard code -> violates principle of context-free service


  • Consumer specifies Return Address(reply channel) in the request message
  • Service provider sends reply message to specified channel 
  • This way, the replier does not need to know where to send the reply, it can just ask the request. If different messages to the same replier require replies to different places, the replier knows where to send the reply for each request.
  • A Return Address is put in the header of a message because it’s not part of the data being transmitted.

Example: JMS Reply-To Property


JMS messages have a predefined property for Return Addresses, JMSReplyTo. Its type is a
Destination (a Topic or Queue), rather than just a string for the destination name, which ensures
that the destination (e.g., Message Channel) really exists, at least when the request is sent.

Queue requestQueue = // Specify the request destination

Queue replyQueue = // Specify the reply destination

Message requestMessage = // Create the request message

requestMessage.setJMSReplyTo(replyQueue);

MessageProducer requestSender =

session.createProducer(requestQueue);

requestSender.send(requestMessage);

Then the receiver would send the reply message like this:

Queue requestQueue = // Specify the request destination

MessageConsumer requestReceiver =

session.createConsumer(requestQueue);

Message requestMessage = requestReceiver.receive();

Message replyMessage = // Create the reply message

Destination replyQueue = requestMessage.getJMSReplyTo();

MessageProducer replySender = session.createProducer(replyQueue);

replySender.send(replyMessage); 



Example: Web Services Request/Response


This SOAP pattern will need to support an optional Return Address to truely make SOAP messages asynchronous and delink the responder from the requestor.
The emerging WS-Addressing standard helps address this issue by specifying how to identify a
web service endpoint and what XML elements to use. Such an address can be used in a SOAP
message to specify a Return Address

No comments:

Post a Comment