我有一个关于JMS createQueue方法的一般性问题。在WebSphere MQ中,这个方法是作为JNDI查找的替代品使用吗?我想我可以动态创建一个队列。这可行吗?谢谢。
QueueSession.createQueue
,这是一个非常具有误导性的方法,它并不像你想象的那样工作:是的,根据规格,并如上述答案所指出的正确。
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()
方法而言,如果已经创建了队列,它将返回对队列的引用。如果未创建,则会抛出JMSException
异常。
还要注意的一点是createTemporaryQueue()
会创建实际物理队列。您必须调用delete()
来清理相关资源。