ActiveMQ-侦听器事件触发后,我是否需要重新订阅队列? [英] ActiveMQ - Do I need to re-subscribe to a queue after the Listener event fires?

查看:177
本文介绍了ActiveMQ-侦听器事件触发后,我是否需要重新订阅队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache.NMS库与ActiveMQ JMS系统集成.对于响应队列侦听器,尚不清楚在收到消息后是否将使用者处理掉.

I am integrating with an ActiveMQ JMS system using the Apache.NMS library. For the response queue listener, it's not clear whether the consumer is disposed after a message is received.

以下是解决方案的摘录:

Here are excerpts from the solution:

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 
}

消费者耐用吗?

收到消息后您是否需要重新订阅?

Do you have to resubscribe after receiving a message?

这是否类似于其他排队/侦听器实现(SQL Server服务代理或TCP/IP侦听器),在其中您需要一个while(true)循环以保持侦听器处于活动状态?

Is this similar to other queuing/listener implementations (SQL Server service broker or the TCP/IP listener) where you need a while(true) loop to just keep the listener active?

推荐答案

由于您使用了这种编码方式,因此我相信(我的.NET生锈),您需要在每条消息上创建一个新的侦听器,作为使用区块将处理消费者.

Because of the way you've coded this, I believe (my .NET is rusty) you would need to create a new listener on each message as the using block will dispose of the consumer.

如果您对事物进行编码,以使使用者是一个成员变量,那么该变量将被保存下来,并且仅在您想停止收听时才关闭,因此不会出现此问题.本质上,using块将处置您要求它管理的资源.

If you coded things such that the consumer was a member variable where it was saved away and only closed when you wanted to stop listening then you would not have this issue. The using block by it's nature will dispose of the resources that you ask it to manage.

这篇关于ActiveMQ-侦听器事件触发后,我是否需要重新订阅队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆