There is no problem, neither with restarts nor with clustering, when using #1. Lookups are only useful in those cases where the ActorRef is not available by any other means.
Best practices for actors lookup from actors
-
29-06-2022 - |
Question
I am using akka 2.2.x. in cluster mode. My question is related to actors lookup.
I have two kind of actors:
processor
. It accepts text and processes it somehowresult collector
. Acceps messages fromprocessor
and summarize the results.
Processor
actor needs to send message to result collector
. So, I need to have ActorRef
inside processor
.
The queston is - how to pass/lookup this ActorRef
to processor
.
I have 3 different solutions for now:
Lookup
ActorRef
toprocessor
in creation time and passActorRef
as contructor parameter. Looks possibly wrong because it does not handle actor restart process and does not fit into cluster environment.Lookup in
preStart
withcontext.actorSelection("../result-collector")
. After this I have the object ofActorSelection
and can send messages with!
. In this solution I am aware of performance degradation because of lookup in cluster before every call. Or am I wrong here?Lookup in
preStart
withcontext.actorSelection("../result-collector")
and callresolveOne
to obtainActorRef
. Looks ok, but may not handle akka cluster changes.
Thanks!
Solution