How to reset a queue in IBM MQ?

2020-03-30 06:16发布

问题:

How do i reset a queue? I want to clear all the messages in the queue, before i start to write a message into a queue. Is there any way i can reset without doing a get call?

MQQueueManager mqQMgr = new MQQueueManager(mqQueueManager);
MQQueue queue = mqQMgr.AccessQueue(getMessageQueue, MQC.MQOO_OUTPUT | MQC.MQOO_INPUT_SHARED | MQC.MQOO_INQUIRE);

There is a .clearmessages in MQMessage object, but i can access that only when i call a get method, i am looking for a way to clear the existing messages in the queue, before i can put a new message into the queue.

回答1:

Messages in a queue can be programatically cleared only with Get calls. There is no other way. Alternatively you use the administrative console to clear messages but that's not what you are looking for.

MQMessage.ClearMessage() discards any data in the message buffer and sets the data offset back to zero. It does not clear all the messages residing in a queue.

May I ask you why you want to clear the queue before putting new messages? What problem are you trying to solve?



回答2:

For clearing messages from a queue you can use the 'Clear Queue' PCF command. As I know, it clears queue faster than GET call, but you can use it only on closed queues. You can read about it in IBM MQ Infocenter: http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzac.doc/pc11350_.htm



回答3:

I have a couple of programs that you can use:

  • ClearQ is a C program that issues MQSC Clear Q command but it will only work if no application has the queue open (restriction of the Clear Q command). ClearQ program can be found here: http://www.capitalware.biz/mq_code_c.html

  • EmptyQ is a Java program that uses MQGET to sequentially remove all messages from the queue. EmptyQ can be found here: http://www.capitalware.biz/mq_code_java.html



回答4:

Maybe this will help!

 private Color[] FloodTest(Color[] color, TouchLocation touch, Texture2D tex)
    {

        Queue<Point> q = new Queue<Point>();
        q.Enqueue(pt);
        while (q.Count > 0)
        {
            if (q.Count > 800000) break; 
        }

        q.Clear();
        q = null;
        return color;
    }

I removed not important code. Please look at q.Count.



标签: c# ibm-mq