From within an Akka actor, how can you find out the nodes of the cluster? That is, the nodes which the local node considers to be currently accessible.
Thanks, - Daniel
From within an Akka actor, how can you find out the nodes of the cluster? That is, the nodes which the local node considers to be currently accessible.
Thanks, - Daniel
Tweaked sample from Typesafe Activator tutorial:
You actually do not need to subscribe to
ClusterDomainEvent
orMemberEvent
. You can just access thestate
member of the Cluster extension, e.g.,One approach could be to have another actor subscribe into
ClusterDomainEvent
messages, specifically looking for the members via theCurrentClusterState
event. That might look something like this:This is kind of a rough outline (might need a few tweaks), but from here, any actor that wanted to know the current members list could send a GetMembers message to this actor via
?
and wait for the response.Now this approach assumes that you might have many actors who want this info. If it turns out that you only had one actor that wants this info then just have that actor subscribe into that event and update its internal state with the members.