我正在编写一个 .NET Windows 窗体应用程序,它将向 Websphere MQ 队列发布消息,然后轮询另一个队列以获取响应。如果返回响应,应用程序将实时处理部分响应。但是响应需要保留在队列中,以便每日批处理作业(也从响应队列中读取)可以完成其余的处理。
我已经阅读了该消息。我无法弄清楚的是如何在不删除它的情况下阅读它。
这是我到目前为止所得到的。我是 MQ 新手,所以任何建议都将不胜感激。并随时用 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
注意:我尚未验证我的代码是否确实删除了该消息。但这就是我理解 MQ 工作的方式,这似乎就是正在发生的事情。如果这不是默认行为,请纠正我。