使用IBM MQ类从队列中浏览,读取和删除消息

Mav*_*751 8 java queue ibm-mq

我正在使用Eclipse的Java类编写一个简单的Java应用程序.

现在,我可以在不删除存储的消息的情况下浏览远程队列.
以下是阅读周期的代码:

MQQueueManager QMgr = new MQQueueManager(qManager); //<-- qManager is a String with the QMgr name

int openOptions = MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_INPUT_SHARED | MQC.MQOO_BROWSE;  

MQQueue queue = QMgr.accessQueue(queueName, openOptions);

MQMessage theMessage    = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
    gmo.options=MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;
    gmo.matchOptions=MQC.MQMO_NONE;
    gmo.waitInterval=5000;

boolean thereAreMessages=true;
while(thereAreMessages){
    try{
        //read the message          
        queue.get(theMessage,gmo);  
        //print the text            
        String msgText = theMessage.readString(theMessage.getMessageLength());
        System.out.println("msg text: "+msgText);

                 // <--- Solution code Here

        //move cursor to the next message               
        gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_NEXT;

    }catch(MQException e){

        if(e.reasonCode == e.MQRC_NO_MSG_AVAILABLE) {
            System.out.println("no more message available or retrived");
        }

        thereAreMessages=false;
    } catch (IOException e) {
        System.out.println("ERROR: "+e.getMessage());
    }
}
Run Code Online (Sandbox Code Playgroud)

主要问题: 在读取消息行之后,在将光标移动到下一条消息之前,如何从队列中删除消息?

次要问题: Eclispe警告我,所有用于选项的costants都已弃用; 哪些是正确的?


解:

这是我真正想要的解决方案:

// set te cursor to remove the message from the queue
gmo.options = CMQC.MQGMO_MSG_UNDER_CURSOR;
queue.get(theMessage, gmo);
Run Code Online (Sandbox Code Playgroud)

这些行必须插入问题代码中

我在这里找到了它:http://www.velocityreviews.com/forums/t124676-mq-series-messages-browse-and-delete.html

Mav*_*751 9

解:

这是我真正想要的解决方案:

// set te cursor to remove the message from the queue
gmo.options = CMQC.MQGMO_MSG_UNDER_CURSOR;
queue.get(theMessage, gmo);
Run Code Online (Sandbox Code Playgroud)

这些行必须插入问题代码中

我在这里找到了它:http://www.velocityreviews.com/forums/t124676-mq-series-messages-browse-and-delete.html