1
votes

I'm very new to the Akka World, much less on Akka-typed. Sorry too if this one's stupid, :(

So, I followed the Request-Response interaction pattern, for actors to interact. That means adding an actorRef in my commands.

However my commands are all in protobuf. I had to serialize the actorRef. How can actor1 deserialize the actorRef of actor2 without knowledge of actor2's ActorSystem?

I've read an answer: (https://manuel.bernhardt.io/2018/07/20/akka-anti-patterns-java-serialization/#comment-157564) But I have trouble understanding the solution... :(

WorkgroupCommand.proto

message WorkgroupCommand {
    oneof sealed_value {
        EnqueueWorkDone enq = 1;
        QueueFull qF = 2;
    }
}

message EnqueueWorkDone {
    required string id = 1;
    required string replyTo = 2; //serialized actorRef
}

Workgroup.scala

private val system1 = ActorSystem(Behaviors.empty, "system-1")

val commandHandler:(State, WorkgroupCommand) => Effect[Event,State] ={
  case (state, EnqueueWorkDone(id, replyTo)) =>
     //how to deserialize replyTo ?????

}

Agent.scala

private val system2 = ActorSystem(mainBehavior, "system-2")
private val resolver = ActorRefResolver(system2.toTyped)

def mainBehavior = Behaviors.setup{ context => 
  //assuming the we have the Workgroup actor
  Workgroup ! EnqueueWorkDone("12345",
                resolver.toSerializationFormat(context.self))

  Behaviors.same
}

Is there a way? Would it help if both the Workgroup and the Agent are children of a main actorSystem?

1

1 Answers

0
votes

val actorRefResolver = ActorRefResolver(system.toTyped)

and then

val serializedActorRef: Array[Byte]= actorRefResolver.toSerializationFormat(replyTo).getBytes(StandardCharsets.UTF_8)

val str = new String(serializedActorRef, StandardCharsets.UTF_8)

val deserializedActorRef = actorRefResolver.resolveActorRef[SomeType.type](str)