Roy Shmuli
Roy Shmuli

Reputation: 5019

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?

Upvotes: 1

Views: 624

Answers (3)

Ruxo
Ruxo

Reputation: 359

You can also create a cluster broadcast router and then gets its routes by sending GetRoutees message to the router. See also https://doc.akka.io/docs/akka/2.3/scala/routing.html#Managagement_Messages

Upvotes: 0

Robert Simmons Jr.
Robert Simmons Jr.

Reputation: 1182

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

Upvotes: 2

Leo C
Leo C

Reputation: 22449

You might want to consider adapting @Patrik Nordwall's answer to a more general find-cluster-nodes question by adding to it your role condition – e.g. add the condition of m.hasRole(role) in case m if m.status == MemberStatus.Up => m.address, etc.

Upvotes: 1

Related Questions