【发布时间】:2012-05-10 19:58:32
【问题描述】:
除了SimpleMessageListenerContainer 选项,不会为临时队列创建消费者。
对于here.面临的一些问题,我不会使用SimpleMessageListenerContainer
以下代码不起作用...(甚至没有创建临时队列)
using (IConnection connection = connectionFactory.CreateConnection())
using (ISession session = connection.CreateSession())
{
IDestination destination = SessionUtil.GetDestination(session, aQueueName);
var replyDestination = session.CreateTemporaryQueue();
// Create a consumer and producer
using (IMessageProducer producer = session.CreateProducer(destination))
{
// Start the connection so that messages will be processed.
connection.Start();
IBytesMessage request = session.CreateBytesMessage(aMsg);
request.NMSReplyTo = replyDestination;
IMessageConsumer consumer = session.CreateConsumer(replyDestination);
consumer.Listener += new MessageListener(this.OnAckRecieved);
// Send a message
producer.Send(request);
ack = this.autoEvent.WaitOne(this.msgConsumeTimeOut, true);
consumer.Close();
consumer.Dispose();
ConnectionFactoryUtils.GetTargetSession(session).DeleteDestination(replyDestination);
}
connection.Close();
session.Close();
以下代码正在运行:-但队列似乎是持久队列而不是临时队列
using (IConnection connection = connectionFactory.CreateConnection())
using (ISession session = connection.CreateSession())
{
IDestination destination = SessionUtil.GetDestination(session, aQueueName);
var replyDestination = session.CreateTemporaryQueue();
// Create a consumer and producer
using (IMessageProducer producer = session.CreateProducer(destination))
{
// Start the connection so that messages will be processed.
connection.Start();
IBytesMessage request = session.CreateBytesMessage(aMsg);
request.NMSReplyTo = replyDestination;
IDestination tempDestination = this.destinationResolver.ResolveDestinationName(session, request.NMSReplyTo.ToString());
IMessageConsumer consumer = session.CreateConsumer(tempDestination);
consumer.Listener += new MessageListener(this.OnAckRecieved);
// Send a message
producer.Send(request);
ack = this.autoEvent.WaitOne(this.msgConsumeTimeOut, true);
consumer.Close();
consumer.Dispose();
ConnectionFactoryUtils.GetTargetSession(session).DeleteDestination(tempDestination);
}
connection.Close();
session.Close();
使用上面的代码(使用 NmsDestinationAccessor)它正在工作。但它创建了一个持久队列。所以当我直接使用临时队列回复目的地时,它不起作用。
【问题讨论】:
-
“未创建”到底是什么意思,CreateConsumer() 是抛出异常还是只返回 null?
-
完全没有错误。当我在 webconsole 上看到时,甚至没有为第二个代码创建临时队列。对于第三个代码,只有消费者没有被创建。
-
从 NMS 项目中添加了一个示例 NUnit 测试以显示它的实际效果。
标签: c# activemq apache-nms