我已经仔细阅读了文档好几次了(http://doc.akka.io/docs/akka/2.1.4/scala/remoting.html http://doc.akka.io/docs/akka/2.1.4/scala/remoting.html)并通过这里的例子(https://github.com/akka/akka/tree/master/akka-samples/akka-sample-remote https://github.com/akka/akka/tree/master/akka-samples/akka-sample-remote)并通过其他人,我仍然不知道如何做我想做的事。我找到的最接近的答案是:如何在 scala 中启动远程 Actor https://stackoverflow.com/questions/12340514/how-to-start-remote-actors-in-scala,但这似乎比我想象的要不方便得多。
我有一个由 12 台机器组成的集群要工作。我想要类似的东西:
val system = ActorSystem("DistributedSystem", ConfigFactor.load.getConfig("distsys"))
val master = system.actorOf(Props(new Master(...)), "master")
然后在 master 内部,有类似这样的内容:
override def preStart() = {
for (i <- 0 until 11) {
// I want each of these actors to be created remotely on
// a different machine
context.actorOf(Props(new RemoteChild(...)), s"child$i")
}
}
这似乎是一个相当常见的用例。是否有我遗漏的东西,或者有没有一个好的方法可以做到这一点(就我的配置应该是什么样子,或者我真正需要多少个 ActorSystems 而言)?我现在正在努力综合一个好的解决方案。
我认为听起来您想要做的是将一组参与者部署到一组远程节点,然后将它们放在本地路由器后面并将消息传递到路由器并让它将工作分配到远程节点。为此,您可以尝试这样的事情:
val addresses = for(i <- 1 until 12)
yield AddressFromURIString(s"akka://[email protected] /cdn-cgi/l/email-protection.$i:2553")
val routerRemote = system.actorOf(Props[RemoteChild].withRouter(
RemoteRouterConfig(RoundRobinRouter(12), addresses)))
这假设您在这些节点上运行 AkkaActorSystem
called RemoteSys
并且它使用为端口 2553 配置的远程处理。当您向该端口发送消息时routerRemote
参考,它现在将在 12 个工作节点之间循环路由消息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)