我读过Active MQ文档,当代理使用创建连接时,代理删除了临时队列。ActiveMQ NMS临时队列在连接关闭时未被破坏
我正在使用Apache NMS v1.5.0和Active MQ 5.1.3,即使连接超出范围,临时队列也始终存在。
我有一个客户端/服务器场景,客户端创建一个临时队列并创建一条消息,在消息的ReplyTo属性中指定临时队列。 然后,服务器组件读取消息并开始将消息发送到对队列的回复。
不幸的是,当客户端关闭它的连接时,它创建的临时队列不会被删除。
下面的代码片段应该说明我的意思。
我创建一个连接,并使用该连接创建一个临时队列。 我关闭连接并创建第二个连接。 我不应该能够使用由第二个连接创建的会话 在临时队列上产生和使用消息,但我可以。
有人可以告诉我,如果我在这里做错了什么。我如何获得活动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();
}
}
我投票结束这个问题作为题外话题,因为它涉及到一个老版本的图书馆。原来的海报在回答中评论说,现在在图书馆的新版本中这不是问题。 –