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 somehow
  • result collector. Acceps messages from processor 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:

  1. Lookup ActorRef to processor in creation time and pass ActorRef as contructor parameter. Looks possibly wrong because it does not handle actor restart process and does not fit into cluster environment.

  2. Lookup in preStart with context.actorSelection("../result-collector"). After this I have the object of ActorSelection 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?

  3. Lookup in preStart with context.actorSelection("../result-collector") and call resolveOne to obtain ActorRef. Looks ok, but may not handle akka cluster changes.

Thanks!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top