Universal Messaging 9.10 | Universal Messaging Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C# | Message Queues | Request Response
 
Request Response
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 username of the requester. This 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 response on the response queue. An example C# .NET 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.
Console.WriteLine("Received request");

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

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

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

//Set recipient of the event to the requester's tag to response.
resp.setSubscriberName(requester.getBytes());
respQueue.push(resp);
An example C# .NET responder is available in the examples section.

Copyright © 2013-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.