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
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
您应该查看订阅集群事件下的文档。这应该解释订阅集群状态更改,此时您将收到一个CurrentClusterState
显示集群当前状态的事件。从那时起,您将开始以其他事件的形式接收增量更改,ClusterEvent.MemberUp
这ClusterEvent.MemberRemoved
有助于您继续跟踪集群中节点的状态。
一种方法是直接CurrentClusterState
通过Cluster
val cluster = Cluster(ActorSystem("MyActorSystem"))
val status = cluster.state.members
val nodes = status.collect {
case m if m.status == MemberStatus.Up => m.address
}