Browse, read, and remove a message from a queue using IBM MQ classes(使用 IBM MQ 类浏览、读取和移除队列中的消息)
问题描述
我正在使用 Eclipse 的 Java MQ 类编写一个简单的 Java 应用程序.
I'm writing a simple Java application using MQ classes for Java with Eclipse.
现在我可以浏览远程队列而无需删除存储的消息.
下面是阅读循环的代码:
Right now I'm able to browse a remote queue without removing the messages stored.
Here is the code of the reading cycle:
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());
    }
}
主要问题:在读取消息行之后,将光标移动到下一条消息之前,如何从队列中删除消息?
Main question: After the read message line and before moving the cursor to the next message how can I remove the message from the queue?
次要问题:Eclispe 警告我,所有用于选项的成本都已弃用;哪些是正确的?
Secondary question: Eclispe is warning me that all the costants used for the options are deprecated; which are the correct ones to use?
解决方案:
这里是我真正想要的解决方案:
Here the solution I'm really looking for:
// set te cursor to remove the message from the queue
gmo.options = CMQC.MQGMO_MSG_UNDER_CURSOR;
queue.get(theMessage, gmo);
这些行必须插入问题代码中
these lines have to be inserted in the question code
我在这里找到了它:http://www.velocityreviews.com/forums/t124676-mq-series-messages-browse-and-delete.html
推荐答案
解决方案:
这里是我真正想要的解决方案:
Here the solution I'm really looking for:
// set te cursor to remove the message from the queue
gmo.options = CMQC.MQGMO_MSG_UNDER_CURSOR;
queue.get(theMessage, gmo);
这些行必须插入问题代码中
these lines have to be inserted in the question code
我在这里找到了它:http://www.velocityreviews.com/forums/t124676-mq-series-messages-browse-and-delete.html
这篇关于使用 IBM MQ 类浏览、读取和移除队列中的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 IBM MQ 类浏览、读取和移除队列中的消息
 
				
         
 
            
        基础教程推荐
- 不推荐使用 Api 注释的描述 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
						 
						 
						 
						 
						 
				 
				 
				 
				