简体   繁体   中英

How to create a temporary jms queue and connect to it by name?

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

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);    
asadmin> create-jms-resource --restype javax.jms.ConnectionFactory --description "connection factory for XXX" jms/ConnectionFactory



asadmin> create-jms-resource --restype javax.jms.ConnectionFactory --description "connection factory for durable subscriptions"
 --property ClientId=MyID jms/DurableConnectionFactory

Command create-jms-resource executed successfully.

as in glassfish server.it will be create successfully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM