简体   繁体   中英

Why connection.close() not closing out the MQ connection?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM