jms 2 shared subscriber

836 Views Asked by At

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.

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. 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.

I have tried running this against both HornetQ and Tibco and get the same outcome.

message consumers created as follows in a class that implements 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?

1

There are 1 best solutions below

1
On

looks like I should have RTFM. From the JMS 2.0 spec:

"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).