To empty the Message Queue(IBM MQ).
mycompanygrpid parent 0.0.1 4.0.0 com.test.mqtest mymqpom 1.0.0 war Test MQ Test MQ UTF-8 7.0.0.0 1.0.0.0 middleware com.ibm.mq ${webSphereMQVersion} middleware com.ibm.mq.jmqi ${webSphereMQVersion} middleware com.ibm.mq.jmqi.remote ${webSphereMQVersion} middleware com.ibm.mq.jmqi.system ${webSphereMQVersion} middleware com.ibm.mqjms ${webSphereMQVersion} middleware com.ibm.msg.client.commonservices ${webSphereMQClientVersion} middleware com.ibm.msg.client.commonservices.j2se ${webSphereMQClientVersion} middleware com.ibm.msg.client.jms ${webSphereMQClientVersion} middleware com.ibm.msg.client.jms.internal ${webSphereMQClientVersion} middleware com.ibm.msg.client.provider ${webSphereMQClientVersion} middleware com.ibm.msg.client.wmq ${webSphereMQVersion} middleware com.ibm.msg.client.wmq.common ${webSphereMQVersion} middleware com.ibm.msg.client.wmq.factories ${webSphereMQVersion} middleware dhbcore DH610-GOLD org.glassfish javax.jms 10.0-b28
private void emptyIt() { MQQueueManager _queueManager = null; MQQueue queue = null; int openOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INPUT_SHARED; try{ _queueManager = new MQQueueManager(qManager); queue = _queueManager.accessQueue(inputQName, openOptions, null, null, null); System.out.println("EmptyQ: Opened queue "+inputQName); int depth = queue.getCurrentDepth(); System.out.println("EmptyQ: Current depth: " + depth); MQGetMessageOptions getOptions = new MQGetMessageOptions(); getOptions.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_ACCEPT_TRUNCATED_MSG; MQMessage message; while (loopAgain){ message = new MQMessage(); try { queue.get(message, getOptions, 1); }catch (MQException e){ if (e.completionCode == 1 && e.reasonCode == MQException.MQRC_TRUNCATED_MSG_ACCEPTED) { // Just what we expected!! } else{ loopAgain = false; if (e.completionCode == 2 && e.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE){ // Good, we are now done - no error!! } else { System.err.println("EmptyQ: MQException: " + e.getLocalizedMessage()); } } } } // close of while loop System.out.println("EmptyQ: Queue emptied."); }catch (MQException e1){ System.err.println("EmptyQ: MQException: " + e1.getLocalizedMessage()); } finally { if (queue != null){ queue.close(); } if (_queueManager != null){ _queueManager.disconnect(); } } }