akka tips

1、actorSelection,当涉及actor远程通信时,可以使用actorSelection。

context.actorSelection("akka.tcp://app@otherhost:1234/user/serviceB")

当需要对这个actor进行管理的话,可以通过发送

val identifyId = 1

context.actorSelection("akka.tcp://app@otherhost:1234/user/serviceB") ! Identify(identifyId)

Identify是一个所有actor全都认识且会自动回复的的case class,回复ActorIdentity

case ActorIdentity(`identifyId`, Some(ref)) =>
      context.watch(ref)
      context.become(active(ref))
case ActorIdentity(`identifyId`, None) => context.stop(self)  

 

posted on 2017-01-23 17:36  重八  阅读(269)  评论(0编辑  收藏  举报

导航