Reputation: 5336
I am trying to make the simplest async request using an akka Actor using the ask pattern but I keep receiving the akka.pattern.AskTimeoutException
no matter what. What I have is this:
object Users extends Controller {
def newUser = {
val actor = Akka.system.actorOf(Props[UserRegistration])
ActorAction[String](actor, "hello")(Ok(_))
}
}
where the ActorAction
is a wrapper of the usual Async
:
object ActorAction {
def apply[A](actorRef: ActorRef, msg: AnyRef, timeout: Timeout = 5 seconds)(f: A => Result)(implicit m: Manifest[A]): Action[AnyContent] = {
Action {
AsyncResult {
ask(actorRef, msg, timeout).mapTo[A].asPromise.map(f)
}
}
}
}
And the actor does nothing but logs the receiving message and returns it:
class UserRegistration extends Actor {
val log = Logging(context.system, this)
def receive = {
case u => log.info("received " + u); u
}
}
The logging of the message works just fine. I have tried everything but nothing works. Any help is more than welcome!
Play: 2.9.1 Akka: 2.0.2
Stacktrace:
[info] play - database [default] connected at jdbc:postgresql://localhost:5432/ss_dev
[info] play - Application started (Dev)
[info] play - Starting application default Akka system.
[INFO] [12/28/2012 22:10:42.51] [application-akka.actor.default-dispatcher-1] [akka://application/user/$a] received hello
[error] play - Waiting for a promise, but got an error: Timed out
akka.pattern.AskTimeoutException: Timed out
at akka.dispatch.DefaultPromise.result(Future.scala:875) [akka-actor.jar:2.0.2]
at akka.dispatch.Await$.result(Future.scala:74) ~[akka-actor.jar:2.0.2]
at play.api.libs.concurrent.AkkaPromise.await(Akka.scala:43) ~[play_2.9.1.jar:2.0.4]
at play.api.libs.concurrent.Promise$class.await(Promise.scala:55) ~[play_2.9.1.jar:2.0.4]
at play.api.libs.concurrent.AkkaPromise.await(Akka.scala:28) ~[play_2.9.1.jar:2.0.4]
at play.api.libs.concurrent.Promise$class.value(Promise.scala:53) ~[play_2.9.1.jar:2.0.4]
Caused by: akka.pattern.AskTimeoutException: Timed out
at akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:274) ~[akka-actor.jar:2.0.2]
at akka.actor.DefaultScheduler$$anon$6$$anon$7.run(Scheduler.scala:183) ~[akka-actor.jar:2.0.2]
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:94) [akka-actor.jar:2.0.2]
at akka.jsr166y.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1381) [akka-actor.jar:2.0.2]
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) [akka-actor.jar:2.0.2]
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) [akka-actor.jar:2.0.2]
Thanks in advance!
Upvotes: 2
Views: 3478
Reputation: 26579
You're not replying to the message sender ! u
, please read the Akka Reference Documentation: http://doc.akka.io
Upvotes: 2