0

I have two instances of my app subscribing to a topic. Since there are two instances(i.e two subscribers), two events(messages) will be generated and written to a queue. (Now i have duplicate message in the queue and one by one each is going to be processed) But I want to have a solution where only one event is processed/or only one message is written to the queue. How can i achieve that?. I must have two subscribers instead one goes down

coder
  • 231
  • 3
  • 11

1 Answers1

1

JMS topics follow publish-subscribe semantics where every subscriber will get the message. However, JMS queues follow point-to-point semantics where only 1 of the connected consumers will receive the message. Therefore, if you want the message to be consumed by only one client then all of your consumers should be connected to a JMS queue rather than a topic.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
  • HI Justin thank you for your response. But I must have two subscribers in case one goes down. Since there are two subscribers there would be two messages on the queue and both will be processed. How can i avoid processing of both the messages? – coder Oct 16 '18 at 14:16
  • @coder, there will be one message in the queue. So first subscriber gets message and tries to process it. If processing completed successfully then subscriber acknowledges that message was processed and message is removed from the queue. If processing failed (due to subscriber down or whatever) then message is not acknowledged and could be processed by second subscriber – Ivan Oct 16 '18 at 14:18
  • If i have two subscribers, there will be two notifications generated correct and two messages will be written to the queue – coder Oct 16 '18 at 15:44
  • Subscribers only receive messages. They don't send them. The number of subscribers has no impact on how many messages the broker actually receives from producers. I'm not clear on what the problem actually is here. – Justin Bertram Oct 16 '18 at 18:00
  • check out https://stackoverflow.com/questions/5576415/jms-topic-vs-queues – Axel Podehl Oct 18 '18 at 15:09