gpt4 book ai didi

java - 为 JMS 2.0 使用者设置 clientID

转载 作者:行者123 更新时间:2023-12-01 22:07:45 26 4
gpt4 key购买 nike

在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com