【问题标题】:ActiveMQ NMS Temporary Queue not destroyed when Connection is closed连接关闭时 ActiveMQ NMS 临时队列未销毁
【发布时间】:2013-08-31 11:02:45
【问题描述】:

我在 Active MQ 文档中读到,当用于创建临时队列的连接关闭时,临时队列会被代理删除。

我使用的是 Apache NMS v1.5.0 和 Active MQ 5.1.3,即使连接超出范围,临时队列也始终存在。

我有一个客户端/服务器方案,其中客户端创建一个临时队列并创建一条消息,在消息的 ReplyTo 属性中指定临时队列。 然后服务器组件读取消息并开始将消息发送到回复队列。

不幸的是,当客户端关闭它的连接时,它创建的临时队列并没有被删除。

下面的代码 sn-p 应该说明我的意思。

我创建一个连接,并使用该连接创建一个临时队列。 我关闭连接并创建第二个。 我应该无法使用会话在临时队列上生成和使用消息 由第二个连接创建,但我可以。

如果我在这里做错了什么,谁能告诉我。如何让 Active MQ 删除临时队列。

非常感谢任何帮助。

[Test]
public void TempQueueTest()
{
    var cf = new ConnectionFactory("tcp://activemq-broker:61616");


    using (var connection = cf.CreateConnection())
    {
        connection.Start();

        using (var session = connection.CreateSession())
        {
            var normalQueue = session.GetQueue("normalQueue");

            ITemporaryQueue tempQueue = session.CreateTemporaryQueue();

            using (var producer = session.CreateProducer(normalQueue))
            {

                // create a messasge and put on a normal queue
                //specify the temp queue as the reply to queue

                var mesage = new ActiveMQTextMessage("hello");
                mesage.ReplyTo = tempQueue as ActiveMQDestination;
                producer.Send(mesage);
            }
        }
        connection.Stop();
    }


    // ok, connection has been disposed, so the temp queue should be destroyed

    // create a new connection
    using (var connection = cf.CreateConnection())
    {
        connection.Start();

        using (var session = connection.CreateSession())
        {
            var normalQueue = session.GetQueue("normalQueue");

            using (var consumer = session.CreateConsumer(normalQueue))
            {
                var message = consumer.Receive() as ActiveMQTextMessage;

                // replyToDest is the temp queue created with the previous connection
                var replyToDest = message.ReplyTo;


                using (var producer = session.CreateProducer(replyToDest))
                {
                    // i shouldn't be able to send a message to this temp queue
                    producer.Send(new ActiveMQTextMessage("this shouldn't work"));
                }

                using (var tempConsumer = session.CreateConsumer(replyToDest))
                {
                    // is shouldn't be able to receive messages on the temp queue as it should be destroyed
                    var message1 = tempConsumer.Receive() as ActiveMQTextMessage;
                }
            }

        }
        connection.Stop();
    }

}

【问题讨论】:

  • 我投票结束这个问题,因为它与旧版本的库有关。原始发布者在答案中评论说,现在在较新版本的库中这不是问题。

标签: c# activemq nms


【解决方案1】:

鉴于您使用的旧版本,我不知道有什么方法可以解决这里发生的问题。代码看起来是正确的,但在 NMS 库的 v1.5.0 版本和当前的 1.6.0 之间有大量修复,其中许多修复了临时目标的问题。我建议您尝试继续使用更高版本,看看您的问题是否消失。

现在您可能必须使用 JMX 来访问代理并删除旧的临时目标。

【讨论】:

  • 感谢 Tim - 我已将 Apache.NMS.dll 和 Apache.NMS.ActiveMQ.dll 升级到 v1.6,它似乎已经解决了这个问题!
猜你喜欢
  • 1970-01-01
  • 2015-07-05
  • 2012-03-10
  • 2021-12-08
  • 2018-07-15
  • 1970-01-01
  • 2015-07-01
  • 2016-07-08
  • 1970-01-01
相关资源
最近更新 更多