Akka-如何在分片区域中检索对实体子角色的引用?

时间:2019-05-30 06:52:07

标签: scala akka actor

说我有一个实体,该实体将对其子演员的引用作为其字段之一。我希望能够将该子引用传递给要求它的发件人:

class SomeActor extends FSM[State, Data] {
  when(Idle) {
      case Event(GetChild, _) =>
          val child = context.actorOf(Props[ChildActor])
          sender() ! child
          stay.using(/*save state here*/)

参考请求进入分片区域:

val getChildFuture = someRegion ? Message(id, GetChild)
val child: ActorRef = Await.result(getChildFuture, timeout.duration).asInstanceOf[ActorRef]
// do something with the actor ref here

当我尝试此操作时,我会得到一份报告,说孩子演员的消息/响应没有传递到不正确的信中。

我想要获得子引用的原因是我想将其转换为接收器(即向其发送流),并且我不想继续将字节发送至分片区域并转发将它们添加到SomeActor实体中(我印象中这是昂贵的,您可以对此进行纠正)。

我什至做得正确吗?我也愿意接受其他方法。

0 个答案:

没有答案