如何解决MQJE001:发生了MQException:完成代码2,原因2009

时间:2016-09-22 05:54:49

标签: java ibm-mq

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

            }
        }

1 个答案:

答案 0 :(得分: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这是一个视频教程,解释如何使用MQ Advanced for Developers创建专用的Red Hat虚拟机,使用所有免费和完全许可的软件,包括在何处获取虚拟化软件和Red Hat OS。

完成设置后,创建一个QMgr,配置为像Integration Test QMgr重新创建错误并检查日志。如果你连接OK并且至少无法重新创建错误,你可以回到MQ管理员,因为知道你的代码不是问题。