title: How do I browse a Websphere MQ message without removing it?
body: <p>I'm writing a .NET Windows Forms application that will post a message to a Websphere MQ queue and then poll a different queue for a response. If a response is returned, the application will partially process the response in real time. But the response needs to stay in the queue so that a daily batch job, which also reads from the response queue, can do the rest of the processing.</p>
  
  <p>I've gotten as far as reading the message. What I haven't been able to figure out is how to read it without removing it.</p>
  
  <p>Here's what I've got so far. I'm an MQ newbie, so any suggestions will be appreciated. And feel free to respond in C#.</p>
  
  <pre><code>Public Function GetMessage(ByVal msgID As String) As MQMessage
      Dim q = ConnectToResponseQueue()
      Dim msg As New MQMessage()
      Dim getOpts As New MQGetMessageOptions()
      Dim runThru = Now.AddMilliseconds(CInt(ConfigurationManager.AppSettings("responseTimeoutMS")))
      System.Threading.Thread.Sleep(1000) 'Wait for one second before checking for the first response'
      While True
          Try
              q.Get(msg, getOpts)
              Return msg
          Catch ex As MQException When ex.Reason = MQC.MQRC_NO_MSG_AVAILABLE
              If Now &gt; runThru Then Throw ex
              System.Threading.Thread.Sleep(3000)
          Finally
              q.Close()
          End Try
      End While
      Return Nothing 'Should never reach here'
  End Function
  </code></pre>
  
  <p><strong>NOTE:</strong> I haven't verified that my code actually removes the message. But that's how I understand MQ to work, and that appears to be what's happening. Please correct me if that's not the default behavior.</p>