MQException:MQJE001:尝试从队列中检索消息时,完成代码为"2",原因为"2033" [英] MQException: MQJE001: Completion Code '2', Reason '2033' while trying to retreive a message from a queue

查看:1373
本文介绍了MQException:MQJE001:尝试从队列中检索消息时,完成代码为"2",原因为"2033"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从队列中捕获消息.请注意,该消息具有xml内容.

I try to catch a message from a queue. Note that the message has a xml content.

但是,队列正确接收消息后,在catch (MQException e)块中引发了异常.

However, an exception is throw in the block catch (MQException e) while the message is correctly received by the queue.

MQException:MQJE001:完成代码"2",原因为"2033"

MQException: MQJE001: Completion Code '2', Reason '2033'

请找到以下使用的代码:

Please find below code used:

import com.ibm.mq.MQMessage
import com.ibm.mq.MQGetMessageOptions
import com.ibm.mq.MQQueueManager
import com.ibm.mq.constants.CMQC
import com.ibm.mq.headers.MQRFH2
import com.ibm.MQException

def mqProps = new Hashtable<String, Object>()
mqProps.put(MQConstants.CHANNEL_PROPERTY, 'mychannel')
mqProps.put(MQConstants.PORT_PROPERTY, myport)
mqProps.put(MQConstants.HOST_NAME_PROPERTY, 'myhost')

def qMgr = new MQQueueManager('myqueuemanager', mqProps)
def openOptions = MQConstants.MQOO_OUTPUT | MQConstants.MQOO_INPUT_AS_Q_DEF

def gmo = new MQGetMessageOptions()
gmo.options = CMQC.MQGMO_WAIT + CMQC.MQGMO_FAIL_IF_QUIESCING

def queue = qMgr.accessQueue('myqueue', openOptions)
MQMessage receiveMsg = null
boolean getMore = true
while(getMore) {
    receiveMsg = new MQMessage()

    try {
        // get the message on the queue
        queue.get(receiveMsg, gmo)
        def rfh2 = new MQRFH2(receiveMsg)
        def strucLen = rfh2.getStrucLength()
        def encoding = rfh2.getEncoding()
        def CCSID = rfh2.getCodedCharSetId()
        def format = rfh2.getFormat()
        def flags = rfh2.getFlags()
        def nameValueCCSID = rfh2.getNameValueCCSID()

        def b = new byte[receiveMsg.getDataLength()]
        receiveMsg.readFully(b)
        System.out.println("Data: " + new String(b))
        queue.close()
   } catch (MQException e) {
      if (e.completionCode == CMQC.MQCC_FAILED && e.reasonCode == CMQC.MQRC_NO_MSG_AVAILABLE) {
         // No message - loop again
      }
      else {
         log.info("MQException: " + e.getLocalizedMessage())
         log.info("CC=" + e.completionCode + " : RC=" + e.reasonCode)
         getMore = false
      }
   } catch (IOException e) {
      log.info("IOException:" + e.getLocalizedMessage())
   }

}

您能帮我修复它吗?谢谢.

Could you please help me to fix it? Thank you.

推荐答案

def openOptions = MQConstants.MQOO_OUTPUT | MQConstants.MQOO_INPUT_AS_Q_DEF

def openOptions = MQConstants.MQOO_OUTPUT | MQConstants.MQOO_INPUT_AS_Q_DEF

没有理由同时打开输入和输出队列.另外,您还应该包括MQOO_FAIL_IF_QUIESCING.

There is no reason to open the queue for both input and output. Also, you should include MQOO_FAIL_IF_QUIESCING.

def qMgr =新的MQQueueManager('myqueuemanager',mqProps)def队列= qMgr.accessQueue('myqueue',openOptions)

def qMgr = new MQQueueManager('myqueuemanager', mqProps) def queue = qMgr.accessQueue('myqueue', openOptions)

我强烈建议您使用大写字母,队列管理器和队列名称.而且,这是IBM最佳实践.

I strongly recommend that you use UPPERCASE, queue manager and queue names. Also, it is an IBM Best Practise.

queue.close()

queue.close()

应该在finally子句中调用close方法,否则可能会导致内存泄漏.

The close method should be called in the finally clause otherwise you could get memory leak.

我多次将 MQTEST12L.java (功能正常)发布到StackOverflow.您可以从以MQTest12L为例,说明如何正确编写Java应用程序以从队列中获取消息.

Use MQTest12L as an example on how to correctly code a Java application to get messages from a queue.

这篇关于MQException:MQJE001:尝试从队列中检索消息时,完成代码为"2",原因为"2033"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆