【问题标题】:Akka doc is unclear about how to get an ExtendedActorSystem to deserialize ActorRefAkka 文档不清楚如何让 ExtendedActorSystem 反序列化 ActorRef
【发布时间】:2017-07-02 22:03:26
【问题描述】:

我正在尝试通过 protobuf 序列化/反序列化 ActorRef。根据 Akka 文档,唯一的方法是将 ActorRef 转换为 String,然后将其转换回远程 Actor 系统。

文档提到使用ExtendedActorSystem 进行反序列化(请参阅here)。但是,目前尚不清楚如何获得ExtendedActorSystem

// Serialize
// (beneath toBinary)
val identifier: String = Serialization.serializedActorPath(theActorRef)

// Then just serialize the identifier however you like

// Deserialize
// (beneath fromBinary)
// ==== Where is this extendedSystem from? ====
val deserializedActorRef = extendedSystem.provider.resolveActorRef(identifier)
// Then just use the ActorRef

编辑

我在这里发现了这个问题:Akka (JVM): Serialize an actorref with protobuf within another message,其中提到将ActorSystem 转换为ExtendedActorSystem。这是正确的方法吗?它会一直有效吗?

【问题讨论】:

  • 对这个也很好奇
  • 嘿@stackverflow 你找到ExtendedActorSystem 的解决方案了吗?

标签: akka-cluster


【解决方案1】:

亲爱的@stackoverflower,

每当您使用ActorSystem(...) 时,它都会构建一个ActorSystemImpl 的实例。

类型树看起来像:

ActorSystemImpl extends ExtendedActorSystem

ExtendedActorSystem implements ActorSystem

你可以使用类似的语句

val system: ExtendedActorSystem = ActorSystem(...).asInstanceOf[ExtendedActorSystem]

访问正确的类型自动完成。不幸的是,ActorSystemImpl 的范围仅限于 [akka]

【讨论】:

    猜你喜欢
    • 2016-02-19
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-26
    相关资源
    最近更新 更多