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.