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:

https://doc.akka.io/docs/akka/current/typed/actor-discovery.html#receptionist-scalability

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

https://doc.akka.io/docs/akka/current/typed/from-classic.html#actorselection

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:
https://doc.akka.io/docs/akka/current/typed/cluster-sharding.html#persistence-example

Is there no other option here? I would like to use EventSourcedBehavior with Persistence, but without Clustering. The specific design is:

  • Events consumed from Kafka (thus, no cluster needed)
  • EventSourcedBehaviors represent a state-machine, so the common examples don’t apply. Each Behavior should process events related to a specific ID

So ideally, I would be able to send events to a specific Actor/Behavior. Do I have to use Classic to make this work?

Would it be possible and not completely ridiculous to run each node as a single-node cluster? Seems like overkill just to get simple addressability.