如何在Akka群集中获得对Leader的引用,以便我可以向领导节点发送消息?
代码:
// assume there exists /user/Supervisor actor at the leader node
val leader = { code to get the leader ref }
leader ! SomeMessage
答案 0 :(得分:4)
您可以从Cluster(system).state.leader
获取其地址,也可以收听LeaderChanged
群集域事件,以便在更改时收到通知。