Take a look at IBM MQ

MSMQ has a feature that allows users to peek into a message without actually consuming it. that is, I look at the next message in the queue based on the MessageID. If I am not interested in the message, I can post the message back to the queue (i.e. the unacknowledged ones are added back to the queue and the message ID is maintained).

Similar functionality also exists in RabbitMQ. However, this is not done in a clean way in RabbitMQ. You can simulate viewing messages by unloading a message from the queue and then not sending an acknowledgment, so RabbitMQ will then add that message back to the queue. However, I read that RabbitMQ can reorder messages and increment message IDs when unacknowledged messages are re-added to the queue.

Has anyone encountered this problem before.

Also, is IBM MQ known to support this peeping and searching behavior / functionality?

Regards D

+3


source to share


2 answers


IBM MQ provides the ability to view messages without removing them from the queue. You can start viewing messages from the beginning and repeat all messages in the queue. You can also view a specific message using MessageId or CorrelationId.

Here is a snippet in C # to view the messages in the queue.



    /// <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);
        }
    }

      

+3


source


In IBM MQ, a way to view messages in a queue if they are not too large is the amqsbcg sample program (see Tim's mention). You can use this to print messages to an output file without a destructive get. Then you can parse the file to check the message ID or other required information. If you find a message that matches the criteria you want, you will need to perform a GET with these parameters to actually remove it from the queue.

amqsbcg QUEUENAME QMGRNAME > output.file

      

This example program can be found at

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 operating system. The default location for $ MQ_HOME is:



AIX: / usr / mqm

Unix: / opt / mqm

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

Another possible option might be to support "qload" MO03 pac. It has the ability to allow filtering by post id, CorrelId or group id

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

+2


source







All Articles