我正在使用XMS 7.5客户端访问IBM MQ,并希望了解有关MessageListener的一件事。 当队列中存在多条消息时,
代码如下所示:
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)
答案 0 :(得分:3)
消息一次一个地传递给消费者,消费者是在呼叫receive()
还是设置了消息监听器来接收消息并不重要。
如果是消息侦听器,MQ将在发送下一个合适的消息之前等待OnMessage
(在您的情况下为ProcessNewMessage
)方法返回。