簡體   English   中英

如何創建臨時jms隊列並通過名稱連接到它?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM