Cluster PubSub
Last updated
Last updated
There are situations where one to send messages to all actors in the cluster that have registered interest in a named topic. Cluster pubsub provides a way to implement publish-subscribe communication between actors distributed across multiple nodes.
By encapsulating topic management and message routing, it simplifies the development of reactive and scalable distributed systems in Go. Its design ensures that messages are efficiently delivered to subscribers across the cluster, making it an essential building block for any distributed actor-based application.
Cluster PubSub is activated with the option during the creation of the actor system.
Cluster PubSub requires cluster mode to be activated first.
Cluster PubSub maintain a Topic registry that is managed by a dedicated system actor .
A single instance of TopicActor
when cluster pubsub is enabled is created on all nodes. You register actors to the local TopicActor
by a message using Tell. To unsubscribe actors need to send message using Tell.
Successful Subscribe
and Unsubscribe
is acknowledged with and replies from the local TopicActor
.
Once cluster pubsub is enabled one can access the local instance of from the ActorSystem
.
This is the true pub/sub mode. A typical usage of this mode is a chat room in an instant messaging application.
To publish a message to a given topic, local actors send a using Tell message to the local TopicActor
. The local TopicActor will route the message to all the local subscribers as well as to all the subscribers to the named topic in the cluster.