Get ActorRef to previously spawned EventSourcedBehavior

franDayz :

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.

franDayz :

I finally found it on the documentation. In a typed system, the correct way to handle persistent actors is by using EntityRef with ClusterSharding, as in the example linked below: https://doc.akka.io/docs/akka/current/typed/cluster-sharding.html#persistence-example

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I get the ActorRef from Source.actorRef()?

How to get Akka actor by name as an ActorRef?

Processes spawned on connected nodes get same PID

Node.js get pid of a spawned process

How do I get the pid of a spawned process using pexpect?

Node.js can't get output of spawned process

Get process ids of all spawned processes from xargs

How to get the exit code of spawned process in expect shell script?

How to get the output of a spawned child_process in Node.JS?

How can I get return value from a spawned process in Erlang?

How to get all currently spawned vehicles in sumo through traci

How to get list of all child process spawned by a script

Get process id of spawned process in Python Pebble library?

Expect: How to get the exit code from spawned process

How to get a reference to a previously forked process in a module?

Get signature of previously purchased item In App Billing

Get output of previously run rake task

How to get inline keyboard for a previously sent message?

Previously entered values get disappeared in JSF datatable

Click on a element and get a previously elements text in jquery

How to get previously stored $_SESSION value?

Get properties from previously resolved promise?

What's the best way to get an ActorRef from a Cluster given a relative path?

Scala akka typed: how to get ActorRef to Actor from it's instance and send message itself?

How can I get the ActorRef from the Receptionist so my actor can send messages to that actor

Akka 2.6 Actor Discovery In A Non-Actor Class (Get ActorRef Outside ActorSystem)

Can I get the name of the class and method within which the current thread was spawned?

Does the code of a Node.js child process get parsed every time it gets spawned?

Why does a task spawned with `task::spawn` not get executed when it's inside of a loop, inside another blocking task?