关闭 MQ 连接

发布于 2024-10-09 15:42:26 字数 3321 浏览 4 评论 0原文

下午好,我编写了一个从 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) {}}
        }

Good afternoon, I wrote a project to Get Park Queue Info from the IBM MQ, it has producing an error when attempting to close the connection though. It is written in java.
Under application in Event Viewer on the MQ machine it displays two errors. They are:

“Channel program ended abnormally.
Channel program ‘system.def.surconn’ ended abnormally. Look at previous error messages for channel program ‘system.def.surconn’ in the error files to determine the cause of the failure.

The other message states:
“Error on receive from host rnanaj (10.10.12.34)
An error occurred receiving data from rnanaj (10.10.12.34) over tcp/ip. This may be due to a communications failure. The return code from tcp/ip recv() call was 10054 (X’2746’). Record these values.”

This must be something how I try to connect or close the connection, below I have my code to connect and close, any ideas??

Connect:

_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();
            }

        }

Close:

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) {}}
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浸婚纱 2024-10-16 15:42:26

根据连接对象的 Javadoc,该函数stop() 方法的内容是...

暂时停止连接
传入消息的传递。

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

As per the Javadoc for the connection object, the function of the stop() method is...

Temporarily stops a connection's
delivery of incoming messages.

So stop() doesn't actually sever the connection. You want the close() method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文