【问题标题】:How to solve MQJE001: An MQException occurred: Completion Code 2, Reason 2009如何解决 MQJE001:发生 MQException:完成代码 2,原因 2009
【发布时间】:2018-07-09 06:29:07
【问题描述】:

我在从 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);
                }

            }
        }

【问题讨论】:

  • 您是否检查了this 的潜在原因?
  • 你想连接什么样的频道?该名称暗示了发送者或接收者通道。您需要连接到服务器连接通道。
  • 它的服务器连接通道
  • 查看 AMQERR01.LOG,但我同意前面的评论 - 通道名称看起来像 SDR(基于队列管理器名称)而不是 SVRCONN。如果它确实是 SVRCONN,那么将其命名为 SDR/RVCR 对并不是一个好习惯 :)

标签: java ibm-mq


【解决方案1】:

根据看起来像 MCA 通道而不是 MQI 通道的命名,评论者是正确的。但是,当我测试与 RCVR 频道的客户端连接时,我会返回 2539=MQRC_CHANNEL_CONFIG_ERROR

另一方面,当使用连接到 MQI 通道的客户端时,出现 2009 的原因有很多。几乎所有这些都出现在 QMgr 的错误日志中,所以如果问题是“如何解决 2009 年?”答案是“通过重新创建错误并立即查看 QMgr 的 AMQERR01.LOG 文件。”

一些可能性包括...

  • 由出口关闭。
  • CONNAUTH 关闭。
  • QMgr 资源错误。
  • 频道已被配置锁定。

许多 MQ 开发问题只能通过查看队列管理器生成的诊断消息来解决。除其他原因外,限制可能泄露给攻击者的信息是安全设计的一部分。 MQ 管理员知道细节是可以的,但攻击者应该得到一个相当模糊的结果。在合法的应用程序开发环境中,开发人员应该能够访问攻击者无法访问的 QMgr 诊断信息。所以去获取错误日志。

如果由于某种原因您无法说服 MQ 管理员提供日志数据或无法访问,您可以在桌面上设置自己的功能齐全、完全许可的免费 MQ 服务器。有关如何下载 MQ Advanced for Developers 的信息可从 标签 wiki 获得。 (将鼠标悬停在标签上,然后从弹出对话框中单击“信息”即可。)

您还可以观看No-Cost, Fully Licensed IBM MQ Sandbox,这是一个视频教程,介绍了如何使用所有免费和完全许可的软件,使用所有免费和完全许可的软件创建专用的 Red Hat 虚拟机,包括从哪里获得虚拟化软件和 Red帽子操作系统。

设置完成后,创建一个配置为类似集成测试 QMgr 的 QMgr,重新创建错误并检查日志。如果您连接正常并且无法重新创建错误,至少您可以返回 MQ 管理员,知道问题不是您的代码。

【讨论】:

    猜你喜欢
    • 2021-05-06
    • 2021-06-08
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多