简体   繁体   English

消息在IBM MQ中查看

[英]Message peek in IBM MQ

In MSMQ there is a functionality that lets users to peek at a message without actually consuming it. 在MSMQ中,有一项功能可以让用户在不实际使用消息的情况下查看消息。 ie I peek at the next message in a Queue based on MessageID. 即我基于MessageID查看队列中的下一条消息。 If I am not interested in the message I can put the message back into the Queue (ie unacknowledged are added back to the Queue and the messageID is maintained). 如果我对消息不感兴趣,我可以将消息放回队列中(即未确认将被添加回队列并保持messageID)。

Similar functionality also exists in RabbitMQ. RabbitMQ中也存在类似的功能。 However in RabbitMQ its not done in a clean way. 但是在RabbitMQ中,它并没有以干净的方式完成。 You can simulate peeking messages by taking the message off the queue and then not sending an acknowledgement so RabbitMQ will then add that message back to the queue. 您可以通过从队列中取消消息然后不发送确认来模拟偷看消息,以便RabbitMQ将该消息添加回队列。 However I read that RabbitMQ can reorder the messages and increment message IDs when unacknowledged messages are re-added to the queue. 但是我读到,当未确认的消息重新添加到队列时,RabbitMQ可以重新排序消息并增加消息ID。

Has anyone encountered this problem before. 有没有人遇到过这个问题。

Also does any one know if IBM MQ supports this behaviour/functionality of peek and seek? 任何人都知道IBM MQ是否支持peek和seek的这种行为/功能?

regards D 问候D.

IBM MQ provides a way to browse messages without removing them from queue. IBM MQ提供了一种浏览消息的方法,而无需将其从队列中删除。 You can start browsing messages from the beginning and iterate through all messages in a queue. 您可以从头开始浏览消息并遍历队列中的所有消息。 You can also browse a specific message using MessageId or CorrelationId. 您还可以使用MessageId或CorrelationId浏览特定邮件。

Here is snippet in C# for browsing messages in a queue. 这是C#中用于浏览队列中的消息的片段。

    /// <summary>
    /// Browse messages in a queue
    /// </summary>
    private void BrowseMessages()
    {
        MQQueueManager qm = null;
        MQQueue queueGet = null;
        Hashtable mqProps = null;

        try
        {
            mqProps = new Hashtable();
            // Setup properties for connection
            mqProps.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
            mqProps.Add(MQC.HOST_NAME_PROPERTY, "localhost");
            mqProps.Add(MQC.PORT_PROPERTY, 1414);
            mqProps.Add(MQC.CHANNEL_PROPERTY, "QM.SVRCONN");

            // Open connection to queue manager
            qm = new MQQueueManager("QM", mqProps);

            // Open queue for browsing
            queueGet = qm.AccessQueue("Q1", MQC.MQOO_BROWSE | MQC.MQOO_FAIL_IF_QUIESCING);

            // In a loop browse all messages till we reach end of queue
            while (true)
            {
                try
                {
                    // Need to create objects everytime
                    MQMessage msg = new MQMessage();
                    MQGetMessageOptions gmo = new MQGetMessageOptions();

                    // Use browse next option to start browsing
                    gmo.Options = MQC.MQGMO_BROWSE_NEXT;
                    queueGet.Get(msg, gmo);
                    Console.WriteLine(msg.ReadString(msg.MessageLength));
                }
                catch (MQException mqex)
                {
                    // When there are no more messages to browse, the Get call
                    // will throw MQException with reason code MQC.MQRC_NO_MSG_AVAILABLE.
                    // But here we close the queue and break out of loop for all exceptions
                    queueGet.Close();
                    break;
                }
            }
            qm.Disconnect();
        }
        catch (MQException mqex)
        {
            Console.WriteLine(mqex);
        }
    }

In IBM MQ, a way to view messages on the queue if they are not too large in size is the amqsbcg sample program (browse as Tim mentioned). 在IBM MQ中,如果队列中的消息不是太大,则查看队列中的消息的方法是amqsbcg示例程序(如Tim所提到的那样浏览)。 You can use this to dump messages to an output file without doing a destructive get. 您可以使用它将消息转储到输出文件而不进行破坏性获取。 You could then parse the file to check for the message ID or other info you need. 然后,您可以解析文件以检查消息ID或您需要的其他信息。 If you found a message that matched the criteria you needed, you would then have to do a GET with those options to actually remove it from the queue. 如果您找到符合所需条件的消息,则必须使用这些选项进行GET以实际将其从队列中删除。

amqsbcg QUEUENAME QMGRNAME > output.file

This sample program can be found in 此示例程序可以在中找到

AIX/Unix: $MQ_HOME/samp/bin/amqsbcg
Windows: $MQ_HOME\tools\c\Samples\Bin\amqsbcg.exe

Where $MQ_HOME is the appropriate location for your operation system. 其中$ MQ_HOME是操作系统的适当位置。 The default location for $MQ_HOME is: $ MQ_HOME的默认位置是:

AIX: /usr/mqm AIX:/ usr / mqm

Unix: /opt/mqm Unix:/ opt / mqm

Windows: C:\\Program Files\\IBM\\Websphere MQ Windows:C:\\ Program Files \\ IBM \\ Websphere MQ

Another possible option may be the "qload" MO03 support pac. 另一种可能的选择可能是“qload”MO03支持pac。 It has an option to let you filter by Message Id, CorrelId Id or Group Id 它有一个选项,允许您按消息标识,CorrelId标识或组标识进行过滤

http://www-01.ibm.com/support/docview.wss?acss=wmq062007&rs=171&uid=swg24009368 http://www-01.ibm.com/support/docview.wss?acss=wmq062007&rs=171&uid=swg24009368

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM