What is the right way to allow an actor

I have 1000 orders, and I want to create an actor for each unique order. What would be the best way to safely create these actors, ensuring that I have only one unique order?

I tried to use ActorSelection first, then if I cannot find an actor with this id, I use ActorOf to create a new one, but when I start them I get a lot of ActorNotFoundException and when I then try to use ActorOf crashes with InvalidActorNameException.

Example:

try
{
    actorRef = await actorSelection.ResolveOne(TimeSpan.FromMilliseconds(3000));
}
catch (ActorNotFoundException)
{
    actorRef = Actor.EwmsActorSystem.ActorOf<T>(actorId);
}
0
source share
1 answer

Entity Per Child Pattern, , . World Crawler.

, :

var child = Context.Child(entityId.ToString());

if (child == ActorRefs.Nobody)
    child = Context.ActorOf(...); // spawn child actor here

child.Tell(message);

ReceiveTimeout , , .

+3

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


All Articles