如何浏览一个WebSphere MQ消息,而不删除它? [英] How do I browse a Websphere MQ message without removing it?

查看:761
本文介绍了如何浏览一个WebSphere MQ消息,而不删除它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个.NET Windows窗体应用程序将信息发送给WebSphere MQ队列,然后查询不同的队列响应。如果响应返回,应用程序将部分地实时处理的响应。但反应需要保持在队列中,以便每日批处理作业,这也读取响应队列,可以做的处理的其余部分。

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.

下面是我有这么远。我是一个MQ新手,所以任何建议将AP preciated。并随时在C#中做出回应。

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

注意:我没有验证,我的code其实除去该消息。但是,这是我所理解的MQ工作,这似乎是发生了什么。请纠正我,如果这不是默认的行为。

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.

推荐答案

您需要打开与MQOO_BROWSE选项队列。然后在你的第一次读你使用MQGMO_BROWSE_FIRST选项GET。最后,你后续的GET的应该使用MQGMO_BROWSE_NEXT选项。

You need to open the queue with MQOO_BROWSE option. Then on your first read you do a GET using the MQGMO_BROWSE_FIRST option. Finally, your subsequent GET's should use the MQGMO_BROWSE_NEXT option.

注:MQOO是MQ打开选项和MQGMO是MQ获取消息选项

Note: MQOO is MQ open options and MQGMO is MQ Get Message Options.

这篇关于如何浏览一个WebSphere MQ消息,而不删除它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆