Reputation: 31526
I have a question regarding the Ask pattern in Akka.
I am calling an actor using the ask pattern from my application. My application is a normal class (not an actor itself):
(actor1Ref ? msg) mapTo[ResponseMsg]
However the actor which is called above calls a second actor like:
secondActor ! msg(sender)
and it's the second actor which returns the actual response like:
originalSender ! responseMsg
So basically there is an indirection involved and when Actor1 calls Actor2 it uses !
.
I tested the code and it works. But I am not sure if the above is the right way of writing this code.
So should I always use ?
between the actor1 and actor2 calls and try to pipeTo
the results? Or is it OK for me to use !
between intermediate calls and when I want to return to the original caller, just send a message to the reference I pass around?
Upvotes: 2
Views: 170
Reputation: 19497
Your current approach is perfectly fine. In fact, it is preferable to use tell
(!
) for actor-to-actor communication. From the documentation:
There are performance implications of using
ask
since something needs to keep track of when it times out, there needs to be something that bridges aPromise
into anActorRef
and it also needs to be reachable through remoting. So always prefertell
for performance, and onlyask
if you must.[Tell] is the preferred way of sending messages. No blocking waiting for a message. This gives the best concurrency and scalability characteristics.
Upvotes: 2