IT分销/经销中间件

queue.getCurrentDepth() 无法获取队列深度

软件名称:MQ JAVA软件版本:7.0环境平台:WINXP问题描述:编写了一段Java程序来获取 MQ队列的当前深度,程序在执行int depth=queue.getCurrentDepth(); 语句时报错,把这一句去掉程序能正常运行,源代码和错误代码如下:源程序: /*****************************************  ...显示全部
软件名称:MQ JAVA

软件版本:7.0

环境平台:WINXP

问题描述:
编写了一段Java程序来获取 MQ队列的当前深度,程序在执行int depth=queue.getCurrentDepth(); 语句时报错,把这一句去掉程序能正常运行,源代码和错误代码如下:

源程序:

/*****************************************
  * Get Message from the DCS MQ queue
  *
  * @param message
  * @return
  ****************************************/
public static String getMessage() {
  try {
   // 设置将要连接的队列属性
   int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
   MQMessage retrieve = new MQMessage();
   // 设置取出消息的属性(默认属性)
   // Set the put message options.(设置放置消息选项)
   MQGetMessageOptions gmo = new MQGetMessageOptions();
   gmo.options = gmo.options + MQC.MQGMO_SYNCPOINT;// Get messages
   // under sync point
   // control(在同步点控制下获取消息)
   gmo.options = gmo.options + MQC.MQGMO_WAIT; // Wait if no messages
   // on the
   // Queue(如果在队列上没有消息则等待)
   gmo.options = gmo.options + MQC.MQGMO_FAIL_IF_QUIESCING;// Fail if
   // Qeue
   // Manager
   // Quiescing(如果队列管理器停顿则失败)
   gmo.waitInterval = 1000; // Sets the time limit for the
   // wait.(设置等待的毫秒时间限制)
   /* 关闭了就重新打开 */
   if (qMgr == null || !qMgr.isConnected()) {
    qMgr = new MQQueueManager(QMSender);
   }
   
   //将指向提供消息的目标队列
   MQQueue queue = qMgr.accessQueue(QSender, openOptions);
   int depth=queue.getCurrentDepth();

   // 从队列中取出消息
   queue.get(retrieve, gmo);
   int dataLength = retrieve.getDataLength();
   message = retrieve.readStringOfCharLength(dataLength);
   queue.close();
   System.out.println("The message got from " + QSender + " is:n"
     + message
     + "nn~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  } catch (MQException ex) {
   System.out
     .println("A WebSphere MQ error occurred : Completion code "
       + ex.completionCode + " Reason code "
       + ex.reasonCode);
  } catch (IOException ex) {
   System.out
     .println("An error occurred whilst writing to the message buffer: "
       + ex);
  } catch (Exception ex) {
   ex.printStackTrace();
  } finally {
   try {
    qMgr.disconnect();
   } catch (MQException e) {
    e.printStackTrace();
   }
  }
  return message;
}

错误:
MQJE001: 完成代码为“2”,原因为“2038”。
A WebSphere MQ error occurred : Completion code 2 Reason code 2038
java.lang.NullPointerException
at com.ibm.mq.MQMessage.writeString(MQMessage.java:2855)
at Ksec.IPUSGetMessage.writeMessage(IPUSGetMessage.java:128)
at Ksec.IPUSGetMessage.main(IPUSGetMessage.java:160)收起
参与7

查看其它 5 个回答shermantian的回答

shermantianshermantian系统工程师北京蓝海讯通科技有限公司

您的示例是获取消息队列的深度。能不能告诉我如何获取发送队列深度。谢谢!我的邮箱是tianshichuan@oneapm.com

互联网服务 · 2016-02-18
浏览2442

回答者

shermantian
系统工程师北京蓝海讯通科技有限公司

shermantian 最近回答过的问题

回答状态

  • 发布时间:2016-02-18
  • 关注会员:1 人
  • 回答浏览:2442
  • X社区推广