3

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

4

2 回答 2

4

假设您的意思是QueueSession.createQueue,这是一种非常具有误导性的方法,并且不会像您想的那样做:

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

此功能是为客户端需要动态操作队列标识的极少数情况提供的。它允许使用特定于提供者的名称创建队列标识。依赖这种能力的客户端是不可移植的。

请注意,此方法不适用于创建物理队列。队列的物理创建是一项管理任务,不能由 JMS API 启动。一个例外是创建临时队列,这是通过 createTemporaryQueue 方法完成的。

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

于 2009-09-21T17:41:37.243 回答
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,您可以通过这些 API 执行此操作。

createQueue()Session 的方法而言,如果它已经创建,它将返回对 Queue 的引用。如果没有JMSException将被抛出。

还要注意的是createTemporaryQueue()创建实际的物理队列。您将不得不调用delete()清理相关资源。

于 2014-02-13T14:15:22.417 回答