Reputation: 3
I'm using Activemq 5.9.1 and I wanna know how to reject when consumer duplicate in same queue name.
case is here..
(A) consumer is subscribe message with "A" queue name, and (B) consumer also subscribe message with
"A" queue name.
in this case, (A) or (B) consumer will be receive message.
But in my system, don't want that case. so I want to reject if (A) consumer subscribe queue "A", and
(B) consumer try to connect queue name "A", then reject (B) consumer.
if is it possible rejecting consumer, tell me how can I do?
Upvotes: 0
Views: 197
Reputation: 933
You want to use an Exclusive consumer by setting the consumer.exclusive
flag to true as in the following example.
queue = new ActiveMQQueue("TEST.QUEUE?consumer.exclusive=true");
consumer = session.createConsumer(queue);
This will ensure that only the first consumer to connect will be given messages. You will see all consumers connected, but only one will get the messages. You can then use additional consumers as back-ups if you want.
If you don't want it connecting at all, you can always set the client ID the same. An exception will be thrown if you attempt to connect to clients with the same client ID.
Upvotes: 2