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

 收藏

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

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

当我尝试此操作时,我会得到一份报告,说儿童演员的消息/响应未传递给不正确的信件。

The reason I wanted to get the child reference was that I wanted to turn it into a sink (i.e. send a stream to it), and I didn't want to keep sending the bytes to the shard region and have it forward them to the SomeActor entity (I'm under the impression this is costly, and you can correct me on this).

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

回复