为什么Connect.close()不关闭MQ连接?

发布于 2025-02-01 17:21:52 字数 772 浏览 2 评论 0原文

我正在使用Connection.start()启动连接和消费者。RECEIVE()以接收队列中的消息。但是,在关闭连接时,它无法使用Connection.Close()关闭连接。因此,它已经耗尽了连接限制,并提出了排队经理不可用的例外。

背后的原因是什么?以及如何解决?

    connectionWMQ = connectionFactory.CreateConnection();
    connectionWMQ.ExceptionListener = new ExceptionListener(OnXMSException);

    // Create session
    ISession sessionWMQ = connectionWMQ.CreateSession(false, AcknowledgeMode.AutoAcknowledge);

    IDestination destination = sessionWMQ.CreateQueue("QueueName");
    IMessageConsumer consumer=sessionWMQ.CreateConsumer(destination);
    try{
         connectionWMQ.Start();
         var message=(IMessage)Consumer.Receive(TIMEOUTTIME);
         //decoding the msg;

         connectionWMQ.Close();
       }
  catch(Exception ex){
       }

I'm using the connection.start() to start the connection and consumer.receive() to receive the messages from the queue. But while closing the connection, it's not able to close the connection using connection.close(). Due to this it's exhausting the connection limit and throwing an exception that queue manager is not available.

What's the reason behind this? and how to solve it?

    connectionWMQ = connectionFactory.CreateConnection();
    connectionWMQ.ExceptionListener = new ExceptionListener(OnXMSException);

    // Create session
    ISession sessionWMQ = connectionWMQ.CreateSession(false, AcknowledgeMode.AutoAcknowledge);

    IDestination destination = sessionWMQ.CreateQueue("QueueName");
    IMessageConsumer consumer=sessionWMQ.CreateConsumer(destination);
    try{
         connectionWMQ.Start();
         var message=(IMessage)Consumer.Receive(TIMEOUTTIME);
         //decoding the msg;

         connectionWMQ.Close();
       }
  catch(Exception ex){
       }

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

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

发布评论

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

评论(1

想念有你 2025-02-08 17:21:52

成功完成ConnectionFactory.CreateConnection()后,您需要确保最终关闭连接。您提供的代码不能保证这一点,有些呼叫可能会失败,结果会跳过关闭连接。
例如,您可以将所有内容移动到createConnection()后面,然后将CLOSS()呼叫移动到相应的最终块。

After a successful completion of connectionFactory.CreateConnection() you need to make sure to close the connection finally. The code you provide does not guarantee this, there are some calls which could fail, with the result it would skip closing the connection.
You could for example move everything behind CreateConnection() into a try block and move close() call to the corresponding finally block.

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