Scala 检查akka集群中是否存在参与者

Scala 检查akka集群中是否存在参与者,scala,akka,actor,akka-cluster,akka-actor,Scala,Akka,Actor,Akka Cluster,Akka Actor,我遇到了一个场景,我需要检查特定的参与者是否存在,这可以通过指定参与者路径通过ActorSystem.actorSelection方法完成。 但是,当本地节点上存在此类参与者时,此方法可以正常工作。若actor系统由多个节点组成,并且actor存在于另一个节点上,则该方法告诉我们actor不存在。若我给出指定远程参与者系统的字符串,那个么这个方法可以工作。但在actorSelection方法中指定远程actor系统字符串似乎不是一个好主意,因为集群中的节点可以加入和离开。 def getOrC

我遇到了一个场景,我需要检查特定的参与者是否存在,这可以通过指定参与者路径通过ActorSystem.actorSelection方法完成。

但是,当本地节点上存在此类参与者时,此方法可以正常工作。若actor系统由多个节点组成,并且actor存在于另一个节点上,则该方法告诉我们actor不存在。若我给出指定远程参与者系统的字符串,那个么这个方法可以工作。但在actorSelection方法中指定远程actor系统字符串似乎不是一个好主意,因为集群中的节点可以加入和离开。

def getOrCreate(customerId:String,deviceId:String):Future[ActorRef]={ context.system.actorSelection(s)/user/${customerId}{$deviceId}”)?标识(deviceId)映射{ 案例ActorIdentity(`deviceId',None)=> //创建新演员 案例ActorIdentity(`deviceId`,Some(actor))=> 演员 } } 当actor存在于本地节点上时,上述代码工作正常,为了检查actor是否存在于集群中的其他节点上,我必须执行以下操作:

def getOrCreate(customerId: String, deviceId: String): Future[ActorRef] = { context.system.actorSelection(s"akka.tcp://Relay@node1:3503/user/${customerId}{$deviceId}") ? Identify(deviceId) map { case ActorIdentity(`deviceId`, None) => // create new actor case ActorIdentity(`deviceId`, Some(actor)) => actor } } def getOrCreate(customerId:String,deviceId:String):Future[ActorRef]={ context.system.actorSelection(s“akka。tcp://Relay@node1:3503/user/${customerId}{$deviceId}“?标识(deviceId)映射{ 案例ActorIdentity(`deviceId',None)=> //创建新演员 案例ActorIdentity(`deviceId`,Some(actor))=> 演员 } }


是否有更好的方法检查整个akka集群中是否存在actor,而不仅仅是本地节点?

看起来只有在集群中不存在具有相同标识符的actor的情况下,才需要创建actor实例。为此,我认为最好的方法是使用并让Akka负责创建和分发实例。
这还将负责将所有消息路由到正确的节点,在集群大小改变时重新分配参与者等。

看起来,只有在集群中不存在具有相同标识符的参与者时,才需要创建参与者实例。为此,我认为最好的方法是使用并让Akka负责创建和分发实例。 这还将负责将任何消息路由到参与者的正确节点,并在集群大小发生变化时重新分配参与者等

def getOrCreate(customerId: String, deviceId: String): Future[ActorRef] = { context.system.actorSelection(s"akka.tcp://Relay@node1:3503/user/${customerId}{$deviceId}") ? Identify(deviceId) map { case ActorIdentity(`deviceId`, None) => // create new actor case ActorIdentity(`deviceId`, Some(actor)) => actor } }