Search code examples
scalaakkabroadcastakka-cluster

Akka: How to find the current nodes in a cluster by role?


I'm using cluster and I would like to send a message to all nodes by role (selector) in the cluster - similar to broadcast, but response either on first success or all failed. I don't want wait for timeout such as ScatterGatherFirstCompletedGroup

One way come in my mind is to create my own broadcast, but I have to know how many actors I'm waiting for response. In case all of them failed I'll response immediately. Is there way to find the current nodes in a cluster by role?

Or any other suggestion?


Solution

  •  implicit lazy val actorSystem: ActorSystem = ActorSystem("mysystem")
     lazy val cluster = Cluster(actorSystem)
     cluster.state.members.filter(m => m.hasRole("admin"))