I am very new to Akka and therefore an absolute beginner. I am trying get more familiar with it by writing a small personal project with Akka and so I am wondering how to do it “the right way”.
So the basic idea is to build an app that crawls some data. So for the crawling part I built three Actors:
This actor is instantiated everytime a new proxy comes up. This actor maintains the state of the proxy it holds and checks frequently if the proxy is still alive.
This actor checks for new proxies and spawns new ProxyActor’s accordingly. This actor is meant to be a singleton within the Actorsystem and may be called to obtain an alive Proxy (by querying all ProxyActor’s with tail chopping).
This actor is instantiated by any actor who needs to crawl a website. This actor needs access to an alive proxy and therefore needs to talk to ProxiesActor.
Unfortunetly the ProxiesActor/ProxyActor are spawned under a dedicated branch (ActorSystem -> ProxiesActor(1) -> ProxyActor (N)) and the CrawlerActor may be spawned on other branches by whoever actor needs it.
So the point where i am stuck is how to obtain a ProxiesActor instance within every CrawlerActor the right way. The only thing i found to talk to actors outside your branch is the Receptionist-Pattern. Is this the way to go here or do I miss something that may be simpler or better in the context of modelling actors?
If the Receptionist-Pattern is the right choice, I am wondering if its the only way and how it is meant to be used. Do I understand it correctly that it is the only correct way to obtain an ProxiesActor instance by subscribing to the Receptionist (as CrawlerActor) and swap the internal reference to the ProxiesActor every time I get an update from the Receptionist? I was wondering why there is no mechanism to register for specific actor events in this case (like Created or Removed) but only a simple query like servicesWereAddedOrRemoved, which tells me nothing about the concrete actor referenced by getAllServiceInstances.