1

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

4

2 回答 2

5

您应该查看订阅集群事件下的文档。这应该解释订阅集群状态更改,此时您将收到一个CurrentClusterState显示集群当前状态的事件。从那时起,您将开始以其他事件的形式接收增量更改,ClusterEvent.MemberUpClusterEvent.MemberRemoved有助于您继续跟踪集群中节点的状态。

于 2014-04-07T15:21:43.290 回答
2

一种方法是直接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
      }
于 2014-05-28T06:32:14.330 回答