For learning purposes I’m trying to implement a simple play application that gets data from a remote actor. The code for the actor is as follows:
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 package it into a jar and start it from the command line. If I try to send messages to this actor from a Scala console opened from another window, all works fine. Now I want to get the actor from the Play framework. In the Application object I define the following method:
def numbers = Action {
Ok(views.html.numbers(Client.actor.path.name))
}
Then in the models package 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")
}
The numbers.html.scala file:
@(message: String)
@main("Header") {
<h1>@message</h1>
}
So I expect that when I go to 127.0.0.1:9000/numbers, I’d get a page with the path to the server actor. Instead of this, I get <h1>deadLetters</h1>. What do I do wrong and how this should be done correctly?
Please follow the configuration given in
https://groups.google.com/forum/#!topic/akka-user/Vw-B8nQeagk
And also add akka-remote dependency