Play framework 2.0 - deadLetters instead of an actor
For educational purposes, I am trying to implement a simple replay application that receives data from a remote participant. The code for the actor looks like this:
import akka.actor.{Props, ActorSystem, Actor}
class NumbersServer extends Actor {
var number = 0
protected def receive = {
case 'next => {
number += 1
number
}
case 'reset => number = 0
case 'exit => context.stop(self)
case 'get => sender ! number
}
}
object Server {
def main(args: Array[String]) {
val system = ActorSystem("ServerSystem")
val server = system.actorOf(Props[NumbersServer], "server")
}
}
I will pack it in a jar and run it from the command line. If I try to send messages to this actor from the Scala console opened from another window, everything works fine. Now I want the actor to move out of the Play box. In the object, Application
I define the following method:
def numbers = Action {
Ok(views.html.numbers(Client.actor.path.name))
}
Then in the package models
I define the Client object:
object Client {
import play.api.Play.current
val actor = Akka.system.actorFor("akka://ServerSystem@127.0.0.1:2552/user/server")
}
File numbers.html.scala
:
@(message: String)
@main("Header") {
<h1>@message</h1>
}
So, I expect that when I go to 127.0.0.1:9000/numbers
, I would get an outline page to the server actor. Instead, I get <h1>deadLetters</h1>
. What am I doing wrong and how should it be done correctly?
source to share
Please follow the setup given in
https://groups.google.com/forum/#!topic/akka-user/Vw-B8nQeagk
And also add the akka-remote dependency
val appDependencies = Seq(
"com.typesafe.akka" % "akka-remote" % "2.0.2"
)
source to share