问题
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