如何创建一个临时jms队列并按名称连接到它? [英] How to create a temporary jms queue and connect to it by name?

查看:96
本文介绍了如何创建一个临时jms队列并按名称连接到它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为响应创建一个临时队列,但是我需要知道是否有可能连接到临时队列而无需通过message的setJMSReplyTo方法发送响应队列对象,因为回复线程根本无法得到该对象.

I need to create a temporary queue for responses, but I need to know if it is possible to connect to temporary queue without sending response queue object via setJMSReplyTo method of message, because replying thread doesn't get that object at all.

推荐答案

我通过使用InitialContext对象将临时队列绑定到jndi,以便可以从需要使用临时队列的线程中查找临时队列.

I binded my temporary queue to jndi by using InitialContext object, so that I can lookup my temporary queue from thread that needs to use my temporary queue.

jndiContext = new InitialContext();
connectionFactory = (QueueConnectionFactory) jndiContext.lookup("ConnectionFactory");
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
temporaryQueue = session.createTemporaryQueue();       
jndiContext.bind(queueJndiName, temporaryQueue);    
destination = temporaryQueue;
responseConsumer = session.createConsumer(destination);
responseConsumer.setMessageListener(new MyListener());

要获取临时队列,您只需要在需要使用它的代码中查找它即可:

To get temporary queue you just need to lookup it in code where you need to use it:

Context jndiContext = new InitialContext();
queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("ConnectionFactory");
queue = (Queue) jndiContext.lookup(youTemporaryQueueName);    

这篇关于如何创建一个临时jms队列并按名称连接到它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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