[英]jms 2 shared subscriber
I have been seeing some issues in our application where two instances of the application were receiving the same message even though their consumers were created using createSharedConsumer and had the same subscription name. 我一直在我们的应用程序中看到一些问题,即使应用程序的两个实例使用createSharedConsumer创建并具有相同的订阅名称,它们的使用者也收到相同的消息。
At first I thought this might be our app or the way we were using SpringJMS so I created a sample application that creates 3 connection factories. 起初,我以为这可能是我们的应用程序或使用SpringJMS的方式,所以我创建了一个示例应用程序,该示例应用程序创建了3个连接工厂。 These factories are then used to create the message sent to a topic and two listeners within the same application (but as they are using a different connection factory and client ID these should be completely separate) but still both message listeners for the two connections are receiving the message.
然后使用这些工厂创建发送到主题的消息,并在同一应用程序中创建两个侦听器(但由于它们使用不同的连接工厂和客户端ID,因此它们应完全分开),但两个连接的两个消息侦听器仍在接收中消息。
I have tried running this against both HornetQ and Tibco and get the same outcome. 我已经尝试对HornetQ和Tibco进行此操作,并获得相同的结果。
message consumers created as follows in a class that implements MessageListener 在实现MessageListener的类中按以下方式创建的消息使用者
Connection connection = factory.createConnection(userName, password);
Session session = connection.createSession();
MessageConsumer topicReceiver = session.createSharedConsumer(topic, SUBSCRIPTION_NAME);
topicReceiver.setMessageListener(this);
connection.start();
Has anyone who has successfully used the shared consumers from JMS 2.0 point me in the direction of what I am missing? 成功使用过JMS 2.0共享用户的人是否向我指出了我所缺少的方向?
looks like I should have RTFM. 看起来我应该有RTFM。 From the JMS 2.0 spec:
根据JMS 2.0规范:
" 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. " “ 共享的非持久订阅由客户端指定的名称和客户端标识符(如果已设置)标识。如果在首次创建共享的非持久订阅时设置了客户端标识符,则客户端随后希望创建使用者在该共享的非持久订阅上,必须使用相同的客户端标识符。 ”
Therefore as multiple clients can not have the same client identifier you should not set the client identifier if you wish to use shared subscriptions (durable or non-durable). 因此,由于多个客户端不能具有相同的客户端标识符,因此,如果您希望使用共享订阅(持久或非持久),则不应设置客户端标识符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.