Search code examples
javaakkaakka-cluster

Publish and Send strategy in Distributed Publish Subscribe Akka Cluster


I have been studying Akka and I am trying to understand the difference between publish and send strategy and where they are used. In the documentation, it is mentioned that publish strategy is used in an instant messaging application whereas send strategy is used in private chat with one other user in the instant messaging application. When I saw the example code provided by them, they both seemed similar except for the process where the destination/subscriber put/subscribe to the sender/publisher. Can anyone help me with this?!


Solution

  • The main difference is that publish will send the message to all the actors listening to that topic, while send will send it to only one of them.

    That’s why publish is better for a group chat (all participants should display each message) while send is better for a private 1-to-1 chat (there’s only one recipient).