I'm currently working on a project where I need to interface with an IBM system which communicates with the outside world through WebSphere MQ. I need to query the system in a "request-response" fashion using queues, and I will be doing this through a queue manager.
However, I can't quite get my head around how this works in practical terms.
Say I've got multiple instances of the same application which puts a message onto a request queue. The message gets a CorrelationId
and MessageId
upon leaving the application, and a ReplyToQueue
property gets set on each message to make sure that the queue manager knows which queue to put the response onto.
However, how does the queue manager operate the response queue? There is no guarantee with regards to the timing of responses, so how is it that the correct response gets back to the application instance which issued the corresponding request?
I keep thinking of message queues as a FIFO queue where messages must be picked one by one. However, this would mean that instance A could pick a response meant for instance B. Obviously, this can't be how it works.
Then, when I look at the API (com.ibm.mq.MQQueue
) I see that to pick a message I have the chance to provide the CorrelationId
and MessageId
of the request message. Does this mean that when I query the queue manager for a message (with these ID's set), the queue manager iterates through the messages in the queue and returns the matching message? This, on the other hand, would mean that we're not talking about a FIFO queue?
MsgID
andCorrelID
fields so that anyGET
on these fields does not require iterating through all the messages to find the right one. Please see Designing WebSphere MQ applications in the WMQ Infocenter for more discussion on developing queuing apps. – T.Rob