Akka.net is there a way to get or create an actor

For my hierarchy of actors, I do not know all the actors that I need until I process the data with several actors, so I'm looking for a way to return an existing ActorRef or create a new action. This is what I would like the code below to create an actor if it does not exist in "my-id-1" or returns the one that already exists.

Context.ActorOf(MyActor.Props(message), "my-id-1");

The code above will (as documented) throw a InvalidActorNameExceptionif the actor already exists. How can I accomplish this in Akka.net?

+2
source share
1 answer

, , Context.Child(actorName). , , ActorRefs.Nobody, .

:

var child = Context.Child(actorName);
if (Equals(child, ActorRefs.Nobody))
    child = Context.ActorOf(MyActor.Props(message), actorName);
+7

Source: https://habr.com/ru/post/1609843/


All Articles