0

This blog talks about to less use ActorSelection to select an actor.

I have a CatalogActorSystem having 10000 product actors. All these actors have names which is really their ids. If I need to have access to the a product with id for example Product_5000 and should not use ActorSelection, I have to have a collection (Implemented with dictionary or ICollection) of product actors in an actor like CatalogActorsCache and have to iterate all of them to find the right one.

Shouldn't I be using the ActorSelection to locate the right product and not any of my search algorithm or use a Dictionary with the key as the product id?

wonderful world
  • 10,969
  • 20
  • 97
  • 194

1 Answers1

2

In case when you have multiple actors of the same purpose, you may want to access them indirectly, i.e. setting another actor between sender and the recipient. Each actor in Akka.NET has collection of it's children ActorRefs. They can be returned by simply using Child(actorName). Therefore you may use it to your advantage, giving this actor (lets call it Coordinator) ability to spawn your child (Product) actors on demand and/or returning refs to them, when requested.

Some time ago I've created an example, which illustrates this concept in more details.

Bartosz Sypytkowski
  • 7,463
  • 19
  • 36