0
votes

I am listening for messages from an IBM MQ using .Net. When it sees a message it removes the message from the queue automatically. I want to check the schema of the message first. If its not the correct schema I am looking for I want to keep it in the queue.

How do I alter the code to not automatically remove the message from the queue when a message is found?

 int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_FAIL_IF_QUIESCING;
        IBM.WMQ.MQQueueManager mqManager = new IBM.WMQ.MQQueueManager(qmName);

        MQQueue queue = mqManager.AccessQueue(queueName, openOptions);

        MQGetMessageOptions gmo = new MQGetMessageOptions();
        gmo.Options = MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQGMO_WAIT;
        gmo.WaitInterval = MQC.MQWI_UNLIMITED;


        queue.Get(message, gmo);

        //Only remove message from the queue if a schema check of the message has passed
2

2 Answers

2
votes

You can browse the message to see if it is what you need and then do a GET if you determine it is. GET is destructive and removes message from a queue, browse is not destructive but lets you examine contents.

openOptions = MQC.MQOO_BROWSE  // open queue for browsing
0
votes

It is far, far better to hand out queues like candy. If there are 5 different types of schemas that could land in the original queue then you should just use 5 queues.
i.e.

  • ABC.SOMTHING.SHEMA.A
  • ABC.SOMTHING.SHEMA.B
  • ABC.SOMTHING.SHEMA.C
  • ABC.SOMTHING.SHEMA.D
  • ABC.SOMTHING.SHEMA.E

It will make for faster processing and you can have 1 listener for each queue.