I have a bunch of Actors (Akka 2) that need to communicate with a background system synchronously.
Is there something wrong with just having the Actors use a separate dedicated dispatcher and perform the processing synchronously like
def receive = {
case Foo(foo) => sender ! getFooSynchronously(foo)
case Bar(bar) => sender ! getBarSynchronously(bar)
}
or should I use futures like the following?
def receive = {
case Foo(foo) => Future { getFooSynchronously(foo) } pipeTo sender
case Bar(bar) => Future { getBarSynchronously(bar) } pipeTo sender
}
If I am not mistaken, using Futures would allow to ask the Actor for Foo and Bar in parallel and join the results, which is not possible with the synchronous approach. Taking into account that I don't need the parallel processing: is it more efficient to use a dedicated dispatcher and avoid the creation of the futures?
receive
method and your actor will not handle more messages until the synchronous call completes, it could be a perfectly valid decision. – Rob Starling