I am using Play 2.0 and Akka to deploy a web application. I have separated actors based on responsibility, as such actors often need to communicate with each other during a single web request.
For example, given an actor that manages registered devices, it must query another actor that handles the associated user accounts:
class DeviceActor extends Actor {
val accountActorRef = ...
def receive = {
case GetAccountByDeviceId(id:String) =>
val accountId = getAccountIdAssociatedWithDevice(id)
accountActorRef ? GetAccountById(accountId) map {
case account: Account => sender ! account
}
}
}
When calling DeviceActor from my controller, I always get
akka.pattern.AskTimeoutException
When calling
mapon aFutureorPromiseyou are actually registering a callback. The referencesenderis caught in the callbacks closure, butsenderis only appropriately set while theDeviceActoris handling the message.You have to capture the senders reference before the
receivemethod exists: