【问题标题】:Browse, read, and remove a message from a queue using IBM MQ classes使用 IBM MQ 类浏览、读取和移除队列中的消息
【发布时间】:2012-08-27 12:30:55
【问题描述】:

我正在使用 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 警告我,所有用于选项的成本都已弃用;哪些是正确的?


解决方案:

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

// 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

【问题讨论】:

  • 我很抱歉这个错误,现在我的问题(以及之前的其他两个问题)应该更符合要求。我是新手,我每天都在学习如何使用这个平台。我将标记答案以在允许后立即关闭它。
  • 如何在单个命令中清除?我的队列中有 1000 条消息,对于大量消息,此步骤不是超级快。

标签: java queue ibm-mq


【解决方案1】:

解决方案:

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

// 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

【讨论】:

  • 在 .NET C# 接口中对我来说基本相同:MQGetMessageOptions mqGetMessageOptionsDel = new MQGetMessageOptions(); mqGetMessageOptions.Options = MQC.MQGMO_MSG_UNDER_CURSOR; queueIn.Get(mqMessage, mqGetMessageOptionsDel);
  • 如何清除 1000 条消息
【解决方案2】:

要删除消息,请按照MQ documentation 中描述的步骤操作。

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

MQC.MQOO_INPUT_SHARED --> CMQC.MQOO_INPUT_SHARED

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-28
    • 1970-01-01
    • 2020-06-02
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多