Search code examples
c#ibm-mqxms

MessageListener, will it get concurrent messages


I'm using XMS 7.5 client to access the IBM MQ and wanted to know one thing about MessageListener. When there are multiple messages are present on the queue,

  • will the associated MessageListener method (i.e, ProcessNewMessage in the below code)called concurrently? OR
  • The messages will be dispatched to the MessageListener(i.e, ProcessNewMessage in the below code) method only at a time?

The code is something like 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)

Solution

  • Messages are delivered one at a time to consumer, it does not matter whether the consumer is calling receive() or has setup a message listener to receive messages.

    In case of a message listener, MQ will wait for the OnMessage (in your case ProcessNewMessage) method to return before delivering the next suitable message.