Setting clientID for JMS 2.0 consumer

痞子三分冷 提交于 2021-01-29 18:47:22

问题


With JMS 1.x the clientId is used to uniquely identify clients when creating durable subscriptions. This answer explains clientId usage in JMS 1.x

With JMS 2.x clientId is made optional. I want to understand pros and cons of supplying the clientId in JMS 2.x.

From an 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.

It sounds like the subscription name is the unique identifier now, but then why have the clientID? These are a new methods on the session class so it can't be backwards compatibility. Any benefits or downsides of setting the clientId with JMS 2.x?

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

回答1:


The JMS 2 specification indicates why the client ID exists in section 6.1.3:

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.

Regarding shared non-durable subscriptions the spec says this in section 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.

The spec says the same basic thing about shared durable subscriptions in section 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.

By making the client identifier optional for shared durable and non-durable subscriptions it makes sharing the subscription a bit more convenient since each client only needs to supply the subscription name rather than both the client identifier and the subscription name. This fits with the general theme of JMS 2 which simplifying the API to make JMS more convenient to use.



来源:https://stackoverflow.com/questions/58679284/setting-clientid-for-jms-2-0-consumer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!