JMS CreateQueue问题

时间:2009-09-21 17:32:55

标签: java jms ibm-mq

我对JMS createQueue方法有一般性的疑问。在WebSphere MQ中,此方法是否用作JNDI查找的替代方法?我以为我可以动态创建一个队列。这可能吗?谢谢。

2 个答案:

答案 0 :(得分:3)

假设你的意思是QueueSession.createQueue,这是一种非常误导性的方法,并没有做你想象的那样:

  

在给定队列的情况下创建队列标识   名。

     

该设施是为罕见的   客户需要的情况   动态操纵队列标识。   它允许创建队列   与提供者特定的身份   名称。依赖于此的客户   能力不便携。

     

请注意,此方法不适用于此   创建物理队列。该   物理创建队列是一种   行政任务,不是   由JMS API发起。唯一的那个   例外是临时的创建   队列,这是由完成   createTemporaryQueue方法。

JMS API不提供动态创建队列的方法(除非您的意思是临时队列,这是请求 - 响应消息传递使用的非常不同的野兽)。如果你想创建队列是运行时,那将是WebSphere专有的。

答案 1 :(得分:1)

是根据规格并在上面的答案中正确指出

Creates a queue identity given a Queue name.

This facility is provided for the rare cases where clients need to dynamically
manipulate queue identity. It allows the creation of a queue identity with a
provider-specific name. Clients that depend on this ability are not portable.

Note that this method is not for creating the physical queue.
The physical creation of queues is an administrative task and is not to be
initiated by the JMS API. The one exception is the creation of temporary queues,
which is accomplished with the createTemporaryQueue method.

因此,JMS不提供动态创建队列的直接方法。它的完成方式将特定于JMS提供者。 JMS提供程序可以提供某种控制台或管理API,您可以通过它来执行此操作。

就考虑Session的createQueue()方法而言,如果已经创建了Queue,它将返回对Queue的引用。如果不是JMSException将被抛出。

另请注意,createTemporaryQueue()创建实际的物理队列。您必须致电delete()来清理相关资源。