【问题标题】:How to start Websphere Mq Service?如何启动 Websphere Mq 服务?
【发布时间】:2018-07-08 17:07:42
【问题描述】:

我使用的是 Web sphere 7.5 版,是否需要 System Broker 来启动 MQ 服务。当我通过 Java 代码访问时,如何启动 MQ 服务。目前我通过代码访问时遇到以下异常

MQJE001:发生 MQException:完成代码 2,原因 2009 MQJE016:MQ 队列管理器在连接期间立即关闭通道 关闭原因 = 2009

MQJE001:发生 MQException:完成代码 2,原因 2009 MQJE016:MQ 队列管理器在连接期间立即关闭通道 关闭原因 = 2009

com.ibm.mq.MQException:MQJE001:发生 MQException:完成代码 2,原因 2009

MQJE016:MQ 队列管理器在连接期间立即关闭通道 关闭原因 = 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);
                }

            }
        }

我收到以下错误日志 9/24/2016 14:09:24 - 进程(1956.7)用户(MUSR_MQADMIN)程序(amqrmppa.exe) 主机(ABHI-PC) 安装(Installation1) VRMF(7.5.0.2) QMgr(QM_ORANGE)

AMQ9208:从主机 Aneesh (192.168.0.7) 接收时出错。

说明: 通过 TCP/IP 从 Aneesh (192.168.0.7) 接收数据时出错。这个 可能是由于通讯故障。 行动: TCP/IP recv() 调用的返回码是 10054 (X'2746')。记录这些 值并告诉系统管理员。

【问题讨论】:

  • 你看过here的一些建议吗?
  • 我是否必须启动任何 服务 才能通过 Java 访问 MQ。如果是,那么我如何启动服务。我只使用 启动了队列管理器运行mqsc 命令。

标签: ibm-mq


【解决方案1】:

您的应用程序正在read 方法中调用_queueManager.disconnect()。这将关闭与队列管理器的连接。然后您的应用程序使用相同的断开连接的 _queueManager 对象调用 accessQueue 方法。这将因连接错误而失败。

建议你把queueManager.disconnect()从read方法中去掉再试试。

更新

几个建议:

1) 通过添加此行 MQEnvironment.properties.put(MQConstants.TRANSPORT_PROPERTY,CMQC.TRANSPORT_MQSERIES_CLIENT) 将传输类型设置为客户端

2) 确保您使用的频道QM_ORANGE.QM_APPLE 是服务器连接 (SVRCONN) 类型的频道。

这个问题可能会有所帮助:MQ queue manager closed channel immediately during connect

【讨论】:

  • 评论了queueManager.disconnect(),但没有使用仍然得到相同的异常
  • 我在通话中遇到异常readQ.selectQMgr(); private void selectQMgr() throws MQException { _queueManager = new MQQueueManager(qManager); }
  • 得到以下错误日志请通过并告诉我该怎么做?
  • 完成了这个 MQEnvironment.properties.put(MQConstants.TRANSPORT_PROPERTY,CMQC.TRANSPORT_MQSERIES_CLIENT)
  • 你所说的“只有消息”是什么意思?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多