How do I browse a Websphere MQ message without removing it?
Posted
by jmgant
on Stack Overflow
See other posts from Stack Overflow
or by jmgant
Published on 2009-06-24T15:52:49Z
Indexed on
2010/05/07
6:38 UTC
Read the original article
Hit count: 333
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.
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.
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#.
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 > runThru Then Throw ex
System.Threading.Thread.Sleep(3000)
Finally
q.Close()
End Try
End While
Return Nothing 'Should never reach here'
End Function
NOTE: 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.
© Stack Overflow or respective owner