据我所知,在为持久主题撰写jms主题订阅者时,我需要设置clientId和订阅名称。
但是,在发布TOPIC时设置clientID的目的是什么?我见过人们甚至为发布者/消费者设置了客户端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);
答案 0 :(得分:4)
唯一标识应用程序需要clientId
。在Pub / Sub消息传递模式中使用持久订阅时必须使用它。您可能知道,消息传递提供程序会在脱机时缓存发往持久订阅者应用程序的发布。当此类应用程序再次联机时,消息传递提供程序必须识别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
与缓存的订阅信息进行比较。