【问题标题】:How to create a temporary jms queue and connect to it by name?如何创建一个临时 jms 队列并通过名称连接到它?
【发布时间】:2010-12-07 22:01:26
【问题描述】:

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

【问题讨论】:

  • 最好将您的答案作为真实答案发布并接受。否则,您的问题将始终处于“未回答”类别中,并且在真正回答时会造成混淆。

标签: java queue jms


【解决方案1】:

我使用 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);    

【讨论】:

    【解决方案2】:
    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 服务器一样,会创建成功。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多