2

We have configured our ActiveMQ message broker as a Spring Boot project and there's another Spring Boot application (let's call it service-A) that has a listener configured to listen to some topics using @JmsListener annotation. It's a Spring Cloud microservice appilcation.

The problem:

  • It is possible that service-A can have multiple instances running.
  • If we have 2 instances running, then any message coming on topic gets listened to twice.
  • How can we avoid every instance listening to the topic?
  • We want to make sure that the topic is listened to only once no matte the number of service-A instances.

Is it possible to run the microservice in a cluster mode or something similar? I also checked out ActiveMQ virtual destinations but not too sure if that's the solution to the problem.

We have also thought of an approach where we can decide who's the leader node from the multiple instances, but that's the last resort and we are looking for a cleaner approach.

Any useful pointers, references are welcome.

Pramod Karandikar
  • 5,289
  • 7
  • 43
  • 68

1 Answers1

1

What you really want is a shared topic subscription which was added in JMS 2. Unfortunately ActiveMQ 5.x doesn't support JMS 2. However, ActiveMQ Artemis does.

ActiveMQ Artemis is the next generation broker from ActiveMQ. It supports most of the same features as ActiveMQ 5.x (including full support for OpenWire clients) as well as many other features that 5.x doesn't support (e.g. JMS 2, shared-nothing high-availability using replication, last-value queues, ring queues, metrics plugins for integration with tools like Prometheus, duplicate message detection, etc.). Furthermore, ActiveMQ Artemis is built on a high-performance, non-blocking core which means scalability is much better as well.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
  • That's not a solution for his problem. As he can't change from topic to queue he may not be able to change the messaging broker – Simon Martinelli Jun 26 '20 at 13:04
  • It's certainly possible that he may not be able to move to a different broker, but he hasn't said that definitively so at this point it's premature to say that this isn't a solution to his problem. Also, he asked for "any useful pointers, references," and that's what this answer is. – Justin Bertram Jun 26 '20 at 13:44
  • I see. Btw. same did I with recommending queues instead of topics but also this is not an answer just a suggestion – Simon Martinelli Jun 26 '20 at 13:45
  • It is an answer if the questioner accepts it as such. – Justin Bertram Jun 26 '20 at 13:47