What's the Purpose of setting the clientID for JMS publisher / consumer?

天涯浪子 提交于 2020-03-19 19:34:13

问题


I understand that i need to set the clientId and subscription name when writing the jms topic subscriber for my durable topics.

But Whats the purpose of setting the clientID when publishing the TOPIC ? I have seen people setting the client Id even for publisher / consumer, but no one explained that why it is required.

ConnectionFactory conFactory =  this.getConnectionFactory();
Connection connection = conFactory.createConnection();

connection.setClientID("WHATS_MY_PURPOSE"); // Why do we need clientID while publishing the TOPIC from consumer / publisher

connection.start();
MessageProducer producer = session.createProducer(destination);

回答1:


A clientId is required to uniquely identify an application. It's a must when using a durable subscription in Pub/Sub messaging pattern. As you might be aware, a messaging provider caches publications destined for durable subscriber applications when they are off-line. When such applications come on-line again, a messaging provider has to identify OK, this is the same application that created a durable subscription but went away for reason. Now it has come back. So let me deliver all messages that were published when this application was away. To verify it's the same application, messaging provider compares the clientId of the application with clientId available with cached subscription information.



来源:https://stackoverflow.com/questions/47006972/whats-the-purpose-of-setting-the-clientid-for-jms-publisher-consumer

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