为 JMS 发布者/使用者设置 clientID 的目的是什么?



我知道在为持久主题编写 jms 主题订阅器时需要设置 clientId 和订阅名称。

但是在发布主题时设置客户端ID的目的是什么?我见过人们甚至为发布者/消费者设置客户端 ID,但没有人解释为什么需要它。

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);

需要唯一标识应用程序的clientId。在发布/订阅消息传递模式中使用持久订阅时,这是必须的。您可能知道,消息传递提供程序会在发往持久订阅者应用程序的发布脱机时缓存这些发布。当此类应用程序再次上线时,消息传递提供商必须识别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。为了验证它是否为同一应用程序,消息传递提供程序会将应用程序的clientId与缓存订阅信息的可用clientId进行比较。

相关内容

最新更新