本文介绍了Akka(JVM):在另一条消息中使用protobuf序列化actorref的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下要使用protobuf序列化的scala对象:

I have the following scala object that I would like to serialize with protobuf:

case class Worker(id: String, ref: ActorRef)

我的理解是Akka带有ProtobufSerializer,可用于从中序列化/到ActorRef。因此,我在原型文件中定义了以下消息:

My understanding is that Akka comes with a ProtobufSerializer that I can use to serialize from/to ActorRef. Therefore I defined the following message in a proto file:

message Worker {
    string id = 1;
    bytes ref = 2;
}

但是,静态方法ProtobufSerializer采用的ExtentendActorSystem我手头没有我需要序列化这些消息(通过我的actor的context.system属性仅是一个ActorSystem)。我不确定如何将我的对象实际序列化为protobuf,反之亦然。

However the static methods ProtobufSerializer take an ExtentendActorSystem that I do not have at hand when I need to serialize those messages (only an ActorSystem through the context.system attribute of my actor). I am not sure how to actually serialize my object to protobuf and the other way around.

推荐答案

我不确定在哪种情况下的确如此,但是我能够将ActorSystem简单地转换为ExtendedActorSystem。在我的特定情况下(我将Akka Persistence与Akka Singleton一起使用),似乎工作正常。

I am not sure in which cases it is true, but I was able to simply cast my ActorSystem to an ExtendedActorSystem. In my specific case (I am using Akka Persistence with Akka Singleton) it seems to work fine.

这篇关于Akka(JVM):在另一条消息中使用protobuf序列化actorref的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 00:42