Except SimpleMessageListenerContainer
option, the consumer is not created for temp queue.
I will not use SimpleMessageListenerContainer
for some issues faced here.
Following code is not working...(even the temp queue is not created)
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();
Flollowing code is working:-but the queue seems to be a persistent queue not a temp queue
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();
With the above code(with use of NmsDestinationAccessor) it is working.but it creates a persistent queue. So when i use the temp queue reply destination directly,it is not working.
Note: You must know that you can not use temperory queue in different session.