【发布时间】:2013-02-02 19:03:16
【问题描述】:
编辑请注意,我需要对此 https://github.com/akka/akka/commit/ce014ece3568938b2036c4ccfd21b92faba69607#L13L6 进行反向更改,以使接受的答案与 AKKA 2.1 一起工作,AKKA 2.1 是在 akkas 主页上找到的稳定分布!
我已经阅读了我可以在 AKKA 上找到的所有教程,但没有找到任何“开箱即用”的教程。
使用eclipse,我想创建2个程序。
程序1: 启动演员“joe”并以某种方式使其在 127.0.0.1:some_port 上可用
程序2: 在 127.0.0.1:some_port 获得对演员“joe”的引用。向“joe”发送问候消息。
程序 1 应该在收到消息时打印一些内容。我想使用 AKKA 2.1 在 Eclipse 中运行这个示例。有人可以列出 2 个程序(程序 1 和程序 2)以及执行此操作的工作 application.conf 文件吗?
编辑> 让我告诉你到目前为止我得到了什么:
演员
case class Greeting(who: String) extends Serializable
class GreetingActor extends Actor with ActorLogging {
def receive = {
case Greeting(who) ⇒ println("Hello " + who);log.info("Hello " + who)
}
}
程序1:
package test
import akka.actor.ActorSystem
object Machine1 {
def main(args: Array[String]): Unit = {
val system = ActorSystem("MySystem")
}
}
程序2
package test
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor.actorRef2Scala
object Machine2 {
def main(args: Array[String]): Unit = {
val system = ActorSystem("MySystem")
val greeter = system.actorOf(Props[GreetingActor], name = "greeter")
greeter ! Greeting("Felix")
}
}
application.conf
akka {
actor {
deployment {
/greeter {
remote = "akka://MySystem@127.0.0.1:2553"
}
}
}
}
但是,当我只启动 Program2 并且它输出时,该程序可以工作:
Hello Felix
[INFO] [02/18/2013 12:27:29.999] [MySystem-akka.actor.default-dispatcher-2] [akka://MySystem/user/greeter] Hello Felix
它似乎没有接收到我的 application.conf。我尝试将它放在我的 Eclipse 项目的 ./src/ 和 ./ 文件夹中。没有不同。另外,我知道这确实是降级部署,但我只需要一个 hello world 程序就可以使用 AKKA。我花了这么多时间,却没有得到一个简单的工作应用程序。
【问题讨论】:
-
这些链接都没有提供工作程序的列表。
-
你可以试试remoting上的文档示例
-
请看我现在贴的例子。
-
akka-samples 中的样本有什么问题?
标签: scala akka actor remote-actors