JMS 创建队列问题

3

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

2个回答

4
假设你指的是QueueSession.createQueue,这是一个非常具有误导性的方法,它并不像你想象的那样工作:
创建队列标识符给定队列名称。这个功能是为了那些需要动态操作队列标识符的客户端而提供的,它允许使用特定于提供程序的名称创建队列标识符。依赖此功能的客户端将无法移植。
请注意,此方法不用于创建物理队列。队列的物理创建是一项管理任务,不应由JMS API发起。唯一的例外是创建临时队列,这可以通过createTemporaryQueue方法完成。
JMS API没有提供动态创建队列的方法(除非您指的是请求-响应消息使用的非常不同的临时队列)。如果您想在运行时创建队列,则需要使用WebSphere专有的方法。

你知道WebSphere是否允许动态创建队列吗? - OneTimeResponse
我认为我正在寻找的是一个模型队列对象?http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/index.jsp?topic=/com.ibm.mq.amqzag.doc/fa10420_.htm - OneTimeResponse
我不熟悉WebSphere,对不起,你需要自己解决。 - skaffman
请注意:我在这份文档中找到了我的答案和其他答案: http://publibfp.boulder.ibm.com/epubs/pdf/csqzaw12.pdf - OneTimeResponse

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()方法而言,如果已经创建了队列,它将返回对队列的引用。如果未创建,则会抛出JMSException异常。

还要注意的一点是createTemporaryQueue()会创建实际物理队列。您必须调用delete()来清理相关资源。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接