IBM WebSphere MQ request/reply scenario
Shashi's answer is spot on for many situations, and is in fact the primary method of distributing responses amongst multiple, relatively low volume requesting applications.
A better choice for high-volume services would involve multiple RESPQs. You can provide a separate RESPQ for each instance of REQApp by using Temporary Dynamic Queues to receive the RESPMsgs -- each instance of REQApp would create the TDQ using the MQOPEN function, and specify the RESPQ name in the ReplyToQ attribute of every message it sends out.
With this setup you would not have to worry about sequencing and correlation IDs, as the messages will be returned to the individual RespQs in the same order in which they are processed by the service application.
Of important note here is that TDQs are just that - temporary. When the OPENing application closes the queue - either via MQCLOSE or by terminating - any messages in the TDQ are lost and not recoverable. If this is a issue - that all responses must be processed no matter what - then you would want to one-time allocate a series of permanent dynamic queues (also using MQOPEN), one for each instance of REQApp, and each instance of REQApp must reconnect to that same queue each time.
I hope this helps as well.
It is common practice to use CorrelationId to relate request and response messages. It works this way:
1) Let's assume there are two queues, a REQQ - request queue where messages are put asking another application, service application, to pick up and process and a RESPQ to which the service application puts replies.
2) The requester application (let's call it as REQAPP) puts a request message (REQMSG) to request queue (REQQ). Before sending the message the REQAPP sets ReplyToQ property on the messages to RESPQ. When the request message is sent, the JMS provider updates the sent message with a unique MessageId. The requester application caches this unique MessageId for later use.
3) On the other side of the world, the service application retrieves the REQMSG from REQQ, reads the MessageId and ReplyToQ property from that message, processes the request and prepares appropriate response message RESPMSG. It then sets the CorrelationId property of the RESPMSG to the MessageId read from the REQMSG and puts the reply to ReplyToQ.
4) The requester application when reading replies, it uses the caches MessageId and sets selection criteria as below to read reply message
GET MESSAGE FROM RESPQ WHERE RESPMSG.CORRELATIONID==REQMSG.MESSAGEID
This selection criteria makes sure that correct response messages is retrieved. The key here is the service application must set the CorrelationId on the response message to the MessageId of request message.
Although Queue is FIFO type, MQ implementation provides message delivery on a Priority basis where messages with high priority are delivered first or FIFO basis where message on top of the queue is delivered first. Messages can also be retrieved using selection criteria as explained in above example.
Hope this helped