2
votes

I have Akka application with several actors. Actor tree looks something like this:

             /user
        /one         TARGET
     /two    /three
   SOURCE

In the source actor I have to send message to TARGET actor. However, I don't know how to do it properly.

Resolving ActorRef from ActorSelection every time seems to be very bad.

Are there any patterns?

1
Why does resolving each time seem to be a bad idea? The opposite, caching references, is a bad idea, as the ref can change, when e.g. actor is recreated.michaJlS
@michaJlS Well, ref is not changed if Restart policy is used. What about resolving - it takes sometime and I have to do it per each request, which is bad idea to my mindRahul

1 Answers

0
votes

The two patterns I am aware of and use are:

  1. Pass the ActorRef of TARGET in the original message sent to SOURCE, so that way SOURCE knows to respond to TARGET. This works well when TARGET is different from message to message, and makes unit testing easy.
  2. Resolve the TARGET ActorRef from the ActorSelection once in either an ESB or Service Locator, and pass that through to SOURCE, and use that. This works well when there is exactly one instance of TARGET in the actor system, however it will make unit testing a little more complex.