从 MQ 本地队列获取消息时出现以下异常。这是我的连接代码。运行代码后出现以下异常
MQJE001: An MQException occurred: Completion Code 2, Reason 2009
MQJE016: MQ queue manager closed channel immediately during connect
Closure reason = 2009
MQJE001: An MQException occurred: Completion Code 2, Reason 2009
MQJE016: MQ queue manager closed channel immediately during connect
Closure reason = 2009
com.ibm.mq.MQException: MQJE001: An MQException occurred:
Completion Code 2, Reason 2009
MQJE016: MQ queue manager closed channel immediately during connect
Closure reason = 2009
这是我的代码
public class Demo {
private MQQueueManager _queueManager = null;
public int port = 1422;
public String hostname = "192.168.1.5";//IP OF HOST
public String channel = "QM_ORANGE.QM_APPLE";//channel name
public String qManager = "QM_ORANGE";//queue manager name
public String inputQName = "Q1";//remote q type
public String outputQName = "QM_APPLE";//queue manager
public Demo() {
super();
}
private void init(String[] args) throws IllegalArgumentException {
// Set up MQ environment
MQEnvironment.hostname = hostname;
MQEnvironment.channel = channel;
MQEnvironment.port = port;
}
public static void main(String[] args) {
Demo readQ = new Demo();
try {
readQ.init(args);
readQ.selectQMgr();
readQ.read();
readQ.write();
} catch (IllegalArgumentException e) {
System.out
.println("Usage: java MQRead <-h host> <-p port> <-c channel> <-m QueueManagerName> <-q QueueName>");
System.exit(1);
} catch (MQException e) {
System.out.println(e);
System.exit(1);
}
}
private void read() throws MQException {
int openOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING
+ MQC.MQOO_INPUT_SHARED;
MQQueue queue = _queueManager.accessQueue(inputQName, openOptions,
null, // default q manager
null, // no dynamic q name
null); // no alternate user id
System.out.println("MQRead v1.0 connected.\n");
int depth = queue.getCurrentDepth();
System.out.println("Current depth: " + depth + "\n");
if (depth == 0) {
return;
}
MQGetMessageOptions getOptions = new MQGetMessageOptions();
getOptions.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING
+ MQC.MQGMO_CONVERT;
while (true) {
MQMessage message = new MQMessage();
try {
queue.get(message, getOptions);
byte[] b = new byte[message.getMessageLength()];
message.readFully(b);
System.out.println(new String(b));
message.clearMessage();
} catch (IOException e) {
System.out.println("IOException during GET: " + e.getMessage());
break;
} catch (MQException e) {
if (e.completionCode == 2
&& e.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE) {
if (depth > 0) {
System.out.println("All messages read.");
}
} else {
System.out.println("GET Exception: "+e);
}
break;
}
}
queue.close();
_queueManager.disconnect();
}
private void selectQMgr() throws MQException {
_queueManager = new MQQueueManager(qManager);
}
private void write() throws MQException {
int lineNum = 0;
int openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
try {
MQQueue queue = _queueManager.accessQueue(outputQName, openOptions,
null, // default q manager
null, // no dynamic q name
null); // no alternate user id
DataInputStream input = new DataInputStream(System.in);
System.out.println("MQWrite v1.0 connected");
System.out.println("and ready for input, terminate with ^Z\n\n");
// Define a simple MQ message, and write some text in UTF format..
MQMessage sendmsg = new MQMessage();
sendmsg.format = MQC.MQFMT_STRING;
sendmsg.feedback = MQC.MQFB_NONE;
sendmsg.messageType = MQC.MQMT_DATAGRAM;
sendmsg.replyToQueueName = "ROGER.QUEUE";
sendmsg.replyToQueueManagerName = qManager;
MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the
// defaults,
// same
// as MQPMO_DEFAULT constant
String line = "test message";
sendmsg.clearMessage();
sendmsg.messageId = MQC.MQMI_NONE;
sendmsg.correlationId = MQC.MQCI_NONE;
sendmsg.writeString(line);
// put the message on the queue
queue.put(sendmsg, pmo);
System.out.println(++lineNum + ": " + line);
queue.close();
_queueManager.disconnect();
} catch (com.ibm.mq.MQException mqex) {
System.out.println(mqex);
} catch (java.io.IOException ioex) {
System.out.println("An MQ IO error occurred : " + ioex);
}
}
}
最佳答案
根据看起来像 MCA channel 而不是 MQI channel 的命名,评论员是正确的。但是,当我测试与 RCVR channel 的客户端连接时,我返回 2539=MQRC_CHANNEL_CONFIG_ERROR
。
另一方面,在使用连接到 MQI channel 的客户端时出现 2009 的原因有很多。几乎所有问题都出现在 QMgr 的错误日志中,所以如果问题是“如何解决 2009?”答案是“通过重现错误并立即查看 QMgr 的 AMQERR01.LOG
文件。”
一些可能性包括...
- 由导出关闭。
- 由 CONNAUTH 关闭。
- QMgr 资源错误。
- channel 已配置锁定。
许多 MQ 开发问题只能通过查看队列管理器生成的诊断消息来解决。除其他原因外,限制可能泄露给攻击者的信息是安全设计的一部分。 MQ 管理员知道细节是可以的,但攻击者应该得到一个相当模糊的结果。在合法的应用程序开发环境中,开发人员应该能够访问攻击者无法访问的 QMgr 诊断信息。所以去获取错误日志。
如果由于某种原因您无法说服 MQ 管理员提供日志数据或无法访问日志数据,您可以在桌面上设置您自己的功能齐全、完全许可的免费 MQ 服务器。有关如何下载 MQ Advanced for Developers 的信息,请访问 ibm-mq。标记维基。 (将鼠标悬停在标签上并单击弹出对话框中的“信息”以转到那里。)
您还可以观看No-Cost, Fully Licensed IBM MQ Sandbox这是一个视频教程,解释了如何使用所有免费和完全许可的软件使用面向开发人员的 MQ Advanced 创建专用的 Red Hat 虚拟机,包括从何处获取虚拟化软件和 Red Hat 操作系统。
设置完成后,创建一个配置类似于集成测试 QMgr 的 QMgr,重新创建错误并检查日志。如果您连接正常并且无法重新创建错误,至少您可以返回 MQ 管理员,知道问题不是您的代码。
关于java - MQJE001 : An MQException occurred: Completion Code 2, Reason 2009怎么解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39631222/