Daniel Winterstein
Daniel Winterstein

Reputation: 2556

Akka cluster: Get status information on nodes

Given an Akka ActorSystem object, how can you find out what other nodes are active in the cluster, and what their status is?

Thank you, - Daniel

Upvotes: 1

Views: 1989

Answers (2)

cmbaxter
cmbaxter

Reputation: 35463

You should check out the docs under Subscribe to Cluster Events. That should explain subscribing into cluster state changes at which point you will receive a CurrentClusterState event that shows the current state of the cluster. From that point forward, you will start receiving incremental changes in the form of other events like ClusterEvent.MemberUp and ClusterEvent.MemberRemoved that help you continue to keep track of the state of the nodes in the cluster.

Upvotes: 5

x1ang
x1ang

Reputation: 21

One approach is directly to get CurrentClusterState by Cluster

val cluster = Cluster(ActorSystem("MyActorSystem"))
val status = cluster.state.members

val nodes = status.collect {
        case m if m.status == MemberStatus.Up => m.address
      }

Upvotes: 2

Related Questions