Universal Messaging Developer Guide : Enterprise APIs : Enterprise Developer's Guide for Java : Message Queues : Request Response
Request Response
Subscriber Based Publish
Universal Messaging can easily be used to issue request/response message exchanges. To accomplish this, the requester simply publishes an event to a request queue and then listens for a response to be issued on a response queue. The responder tags this response with the username of the requester, and this ensures that only the requester will see the response event.
Requester
The requester publishes an event to a request queue and then listens for a response to be issued on a response queue. The response will be tagged with the tag of the requester. This tag is specified during the initial configuration of the session, as shown below:

mySession = nSessionFactory.create(nsa, this,"subscriber tag");
After setting this, the requester simply publishes an event to the request queue and listens for a reply on the response queue.
An example Java requester is available in the examples section.
Responder
The responder listens to the request channel and responds to each request event. To ensure the message is only delivered to the correct recipient, the Subscriber Name must be set on the response event. The response event's data can contain the relevant information the user needs.

//Having received a request event req, and established a connection to
//a response queue respQueue.
System.out.println("Received request");

//Retrieve username of request sender.
String requester = req.getPublishUser();

//Construct reply message.
String text = "Response: " + new String(req.getEventData());

//Construct reply event
nEventProperties atr = new nEventProperties();
nConsumeEvent resp = new nConsumeEvent(atr, text.getBytes());

//Set recipient of the event to the requester's tag to reply.
resp.setSubscriberName(requester.getBytes());
respQueue.push(resp);
An example Java responder is available in the examples section.
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback