Get ActorRef to a previously spawned EventSourcedBehavior

We are using event sourcing with Akka Persistence by extending EventSourcedBehavior. When we create the persistent actor we give it an unique name, by using an uuid (the same we use inside create to build the PersistenceId, for entity sharding):

UUID uuid = UUID.randomUUID();
String name = MyBehavior.nameFor(uuid);

ActorRef<Command> actorRef =
    context.spawn(MyBehavior.create(uuid), name);

Later on, when we want to send further commands to the actor, we would like to get an ActorRef<Command> from the context, since the actorRef object reference returned by spawn won’t be in scope anymore. Think about commands as a result of subsequents HTTP requests.

We can’t use context.getChild(name) as it returns ActorRef<Void>.

We’ve also considered actor discovery with Receptionist, but the documentation says it doesn’t scale to any number of actors:

On the other hand, ActorSelection is not supported in typed, as per the following link:

We are not sure about the right approach here. Any help would be much appreciated.

Can you keep it in a Map in the parent actor that spawns them?

Cluster Sharding is otherwise popular to use with event sourced actors. Then they are adressed by id instead of a direct ActorRef.

Thanks @patriknw! Finally found this link which turned out to be what I need: