java - 为 JMS 2.0 使用者设置 clientID

标签 java jms

在 JMS 1.x 中,clientId 用于在创建持久订阅时唯一标识客户端。这个answer解释 JMS 1.x 中 clientId 的用法

对于 JMS 2.x,clientId 是可选的。我想了解在 JMS 2.x 中提供 clientId 的优缺点。

来自 Oracle article on JMS 2.x features :

Shared durable subscriptions. These are available in JMS 2.0 only and are created using createSharedDurableConsumer. They can have any number of consumers. Setting the client identifier is optional. The subscription is identified by the combination of the subscription name and the client identifier, if it is set.

听起来现在订阅名称是唯一标识符,但是为什么要有 clientID 呢?这些是 session 类上的新方法,因此它不能向后兼容。使用 JMS 2.x 设置 clientId 有什么优点或缺点?

MessageConsumer messageConsumer = session.createSharedDurableConsumer(topic, "myDurableSub");

最佳答案

JMS 2 规范在第 6.1.3 节中指出了客户端 ID 存在的原因:

The only use of a client identifier defined by JMS is its mandatory use in identifying an unshared durable subscription or its optional use in identifying a shared durable or non-durable subscription.

关于共享非持久订阅,规范在第 8.3.3 节中说明了这一点:

A shared non-durable subscription is identified by a name specified by the client and by the client identifier if set. If the client identifier was set when the shared non-durable subscription was first created then a client which subsequently wishes to create a consumer on that shared non-durable subscription must use the same client identifier.

规范在第 8.3.4 节中对共享持久订阅说了同样的基本内容:

A shared durable subscription is identified by a name specified by the client and by the client identifier if set. If the client identifier was set when the shared durable subscription was first created then a client which subsequently wishes to create a consumer on that shared durable subscription must use the same client identifier.

通过使客户端标识符对于共享持久和非持久订阅是可选的,可以使共享订阅更加方便,因为每个客户端只需要提供订阅名称,而不需要同时提供客户端标识符和订阅名称。这符合 JMS 2 的总体主题,即简化 API,使 JMS 更方便使用。

关于java - 为 JMS 2.0 使用者设置 clientID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58679284/

相关文章:

java - 如何获得现有的 JMS 队列?

java - 在选择查询java中PrepareStatement不起作用

java - AssertJ:一种检查对象字段值是否包含特定模式(正则表达式)的方法

java - Netbeans:如何动态填充 JTree?

Java 格式 double 到最小精度的字符串

java - 在 jboss EAP 7 中创建 JMS 消息生成器时出错

java - 对象消息未在 Activemq 中反序列化

java - JMS - 消息监听器 onMessage 必须实现两次?

java - Websphere 消息队列多线程

java - 如何配置 Maven 编译器插件以在发生错误时继续并在构建过程结束时显示它们?