关闭MQ连接

时间:2010-12-30 21:38:03

标签: java jms ibm-mq

下午好,我写了一个从IBM MQ获取Park Queue Info的项目,它在尝试关闭连接时产生错误。它是用java编写的。 在MQ计算机上的事件查看器中的应用程序下,它显示两个错误。他们是:

“频道节目异常结束。 频道节目'system.def.surconn'异常终止。查看错误文件中通道程序'system.def.surconn'的先前错误消息,以确定失败的原因。

另一条消息指出: “从主机rnanaj收到错误(10.10.12.34) 通过tcp / ip从rnanaj(10.10.12.34)接收数据时发生错误。这可能是由于通信故障。来自tcp / ip recv()调用的返回码是10054(X'2746')。记录这些值。“

这一定是我尝试连接或关闭连接的方法,下面我有我的代码连接和关闭,任何想法?

连接:

_logger.info("Start");

        File outputFile = new File(System.getProperty("PROJECT_HOME"), "run/" + this.getClass().getSimpleName() + "." + System.getProperty("qmgr") + ".txt");
        FileUtils.mkdirs(outputFile.getParentFile());

        Connection jmsConn = null;
        Session jmsSession = null;
        QueueBrowser queueBrowser = null;
        BufferedWriter commandsBw = null;
        try {
            // get queue connection
            MQConnectionFactory MQConn = new MQConnectionFactory();
            MQConn.setHostName(System.getProperty("host"));
            MQConn.setPort(Integer.valueOf(System.getProperty("port")));
            MQConn.setQueueManager(System.getProperty("qmgr"));
            MQConn.setChannel("SYSTEM.DEF.SVRCONN");
            MQConn.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);

            jmsConn = (Connection) MQConn.createConnection();
            jmsSession = jmsConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Queue jmsQueue = jmsSession.createQueue("PARK");

            // browse thru messages
            queueBrowser = jmsSession.createBrowser(jmsQueue);
            Enumeration msgEnum = queueBrowser.getEnumeration();

            commandsBw = new BufferedWriter(new FileWriter(outputFile));
            //
            String line = "DateTime\tMsgID\tOrigMsgID\tCorrelationID\tComputerName\tSubsystem\tDispatcherName\tProcessor\tJobID\tErrorMsg";
            commandsBw.write(line);
            commandsBw.newLine();

            while (msgEnum.hasMoreElements()) {
                Message message = (Message) msgEnum.nextElement();
                line = dateFormatter.format(new Date(message.getJMSTimestamp()))
                        + "\t" + message.getJMSMessageID()
                        + "\t" + message.getStringProperty("pkd_orig_jms_msg_id")
                        + "\t" + message.getJMSCorrelationID()
                        + "\t" + message.getStringProperty("pkd_computer_name")
                        + "\t" + message.getStringProperty("pkd_subsystem")
                        + "\t" + message.getStringProperty("pkd_dispatcher_name")
                        + "\t" + message.getStringProperty("pkd_processor")
                        + "\t" + message.getStringProperty("pkd_job_id")
                        + "\t" + message.getStringProperty("pkd_sysex_msg");
                _logger.info(line);
                commandsBw.write(line);
                commandsBw.newLine();
            }

        }

关闭:

finally {
            IO.close(commandsBw);
            if (queueBrowser != null) { try { queueBrowser.close();} catch (Exception ignore) {}}
            if (jmsSession != null) { try { jmsSession.close();} catch (Exception ignore) {}}
            if (jmsConn != null) { try { jmsConn.stop();} catch (Exception ignore) {}}
        }

1 个答案:

答案 0 :(得分:1)

根据the Javadoc for the connection objectstop()方法的功能是......

  

暂时停止连接   传递消息。

所以stop()实际上并没有切断连接。您需要close()方法。

相关问题