We are using IBM MQ as a messaging layer with multi instance setup. The .NET application using XMS client (ver 7.5) will read off messages from the multiple Queues. Since the volume of the message is high, I have created around 5 connection per queue to read the messages. And there are 4 such queues. So in the application at any point of time, there are 20 connections and 20 session opened. With this setup I am facing two issues:
Often I get the two XMS exceptions while opening the connections.One is MQRC_HOST_NOT_AVAILABLE ((2538, X’9EA’) The attempt to allocate a conversation to the remote system failed.) and the other is MQRC_CONNECTION_BROKEN(Connection to queue manager lost.)
While closing the application, it is taking lot more time to close of all the sessions and connections because they are too many of them.
So I was thinking to reduce the number of connection. By just creating one connection per queue and open 5 session per queue. In this way, the number of connections will be reduced to 4 (from 20). So both the above said issues will be solved I think (yet to try)
So wanted someone in the know, to share their experience on what is the best practice of handing the above scenario. Will there be any delay in delivering the messages if we open multiple sessions per connection compared to single session per connection?
The code I'm using is below:
private XMSFactoryFactory xMSFactoryFactory;
private IConnectionFactory connectionFactory;
private IConnection connectionWMQ;
private ISession sessionWMQ;
private IDestination destination;
private IMessageConsumer messageConsumer;
xMSFactoryFactory= XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
connectionFactory = _xMSFactoryFactory.CreateConnectionFactory();
// Set queue manager name, set server names, channel, use
// XMSC.WMQ_CM_CLIENT as WMQ_CONNECTION_MODE
connectionWMQ = _connectionFactory.CreateConnection();
sessionWMQ = _connectionWMQ.CreateSession(true, AcknowledgeMode.SessionTransacted);
destination = sessionWMQ.CreateQueue(_queueSettings.QueueName);
messageConsumer = sessionWMQ.CreateConsumer(_destination);
messageConsumer.MessageListener = new MessageListener(ProcessNewMessage)
Not much of action happens on Connection. It's used for creating temporary destinations. Session is where all the actions happens. So just one connection is sufficient.
MQRC_HOST_NOT_AVAILABLE
and MQRC_CONNECTION_BROKEN
may not be due to the number of connections/sessions you are creating because a queue manager can support a large number connections.
Your application is using a transacted session and message listener. How are you committing transaction. Can you show us the code for that? Are you calling commit for every message received?