我正在使用 Apache.NMS 库与 ActiveMQ JMS 系统集成。对于响应队列监听器,消费者是否在收到消息后被释放是不清楚的。
以下是解决方案的摘录:
var destination = getDestination(session, Settings.Instance.OutboundQueue);
// Create a consumer and producer
using (var consumer = session.CreateConsumer(destination))
{
// Start the connection so that messages will be processed.
connection.Start();
consumer.Listener += OnMessage;
var receiveTimeout = TimeSpan.FromSeconds(Settings.Instance.Timeout);
// Wait for the message
semaphore.WaitOne((int)receiveTimeout.TotalMilliseconds, true);
}
// The Listener event
protected void OnMessage(IMessage receivedMsg)
{
var message = receivedMsg as ITextMessage;
semaphore.Set();
// process the message
}
消费者耐用吗?
收到消息后是否需要重新订阅?
这是否类似于其他队列/侦听器实现(SQL Server 服务代理或 TCP/IP 侦听器),您需要一个 while(true) 循环来保持侦听器处于活动状态?