title: IBM WebSphere MQ request/reply scenario
body: <p>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. </p>
  
  <p>However, I can't quite get my head around how this works in practical terms.</p>
  
  <p>Say I've got multiple instances of the same application which puts a message onto a request queue. The message gets a <code>CorrelationId</code> and <code>MessageId</code> upon leaving the application, and a <code>ReplyToQueue</code> property gets set on each message to make sure that the queue manager knows which queue to put the response onto.</p>
  
  <p>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?</p>
  
  <p>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.</p>
  
  <p>Then, when I look at the API (<code>com.ibm.mq.MQQueue</code>) I see that to pick a message I have the chance to provide the <code>CorrelationId</code> and <code>MessageId</code> 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?</p>