MessageListener,它会获得并发消息

时间:2015-08-04 15:31:27

标签: c# ibm-mq xms

我正在使用XMS 7.5客户端访问IBM MQ,并希望了解有关MessageListener的一件事。 当队列中存在多条消息时,

  • 是否会同时调用关联的MessageListener方法(即下面代码中的ProcessNewMessage)? OR
  • 消息将一次只调度到MessageListener(即下面代码中的ProcessNewMessage)方法吗?

代码如下所示:

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 个答案:

答案 0 :(得分:3)

消息一次一个地传递给消费者,消费者是在呼叫receive()还是设置了消息监听器来接收消息并不重要。

如果是消息侦听器,MQ将在发送下一个合适的消息之前等待OnMessage(在您的情况下为ProcessNewMessage)方法返回。