繁体   English   中英

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

[英]Browse, read, and remove a message from a queue using IBM MQ classes

我正在使用 Eclipse 的 Java MQ 类编写一个简单的 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());
    }
}

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

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


解决方案:

这是我真正在寻找的解决方案:

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

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

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

解决方案:

这是我真正在寻找的解决方案:

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

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

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

要删除消息,请按照MQ 文档 中描述的过程进行操作。

对于不推荐使用的常量值,再次检查Javadoc ,描述了推荐的方法。

MQC.MQOO_INPUT_SHARED --> CMQC.MQOO_INPUT_SHARED

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM