Akka (JVM): Serialize an actorref with protobuf wi

2019-09-15 02:55发布

问题:

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

case class Worker(id: String, ref: 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;
}

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.

回答1:

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.