[英]How to create a temporary jms queue and connect to it by name?
我需要为响应创建一个临时队列,但是我需要知道是否可以通过setJMSReplyTo消息方法连接到临时队列而不发送响应队列对象,因为回复线程根本没有得到该对象。
我通过使用InitialContext对象将我的临时队列绑定到jndi,以便我可以从需要使用我的临时队列的线程中查找我的临时队列。
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());
要获得临时队列,您只需在需要使用它的代码中查找它:
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
命令create-jms-resource已成功执行。
在glassfish server.it中将成功创建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.