MessageListener, will it get concurrent messages

2019-08-08 15:39发布

问题:

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)

回答1:

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.



标签: c# ibm-mq xms