软件名称: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)
收起