How can duplicate processing of messages be avoided if two instances of same app subscribes to a topic?

I have two instances of same application running and they both subscribe to same topic. Messages are going to to published to both servers and both servers are going to process that same message. How can duplicate processing of messages be avoided if two instances of same app subscribes to a (same)topic using a stateless approach?

2 answers

  • answered 2018-10-11 19:40 NiVeR

    If the servers are just a replication of each other, they should not have separate sources of data that they will listen to. The whole point of creating multi-instance architecture is to parallelize, and so speed up, processing of things. You should have a single source of data so that the once a message is taken in hand by one server it is not anymore available for the other, which can focus on following messages.

  • answered 2018-10-11 20:20 Vadim

    Topic has exactly opposite purpose from what you try to achieve. Queue stands for it.

    If you still want to use topic you must have only one subscriber/listener on top of your application instances.

    Then you have to force on your own any load balance algorithm between your application instances (e.g. round-robin or something more complex).