MQ - delete all messages from a queue

10,623

Solution 1

You can use a WMQ PCF program to clear messages in queue in one go. PCF classes provide an interface to administer WMQ programatically. There is a sample, PCF_ClearQueue.java that demonstrates clearing messages from a queue.

The sample is located (on Windows platforms) \tools\pcf\samples directory. More information on clear queue can be found here.

Solution 2

If you have access to runmqsc then use the MQSC command called: CLEAR QLOCAL

Note: If an application has the queue open then that command will fail and PCF commands will fail too. Hence, you will need to get all messages from the queue one at a time. You can download a Java program called EmptyQ from http://www.capitalware.com/mq_code_java.html that will do the trick.

Share:
10,623
saravana_pc
Author by

saravana_pc

Updated on July 10, 2022

Comments

  • saravana_pc
    saravana_pc almost 2 years

    I'm new to MQ programming with java. For my Integration tests, I would like to clean up the destination queue before posting any messages to it. Is there any option in MQ-Java to delete all messages in a queue in one go?