无需新的ActorSystem即可远程创建Akka actor [英] Create an Akka actor remotely without a new ActorSystem

查看:127
本文介绍了无需新的ActorSystem即可远程创建Akka actor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经浏览过文档多次( http://doc.akka.io/docs/akka/2.1.4/scala/remoting.html ),并通过此处的示例(如何在Scala中启动远程参与者,但似乎比我想象的要麻烦得多.

I've been over the documentation several times now (http://doc.akka.io/docs/akka/2.1.4/scala/remoting.html) and through the example here (https://github.com/akka/akka/tree/master/akka-samples/akka-sample-remote) and through others, and I still can't figure out how to do what I want to do. The closest answer I've found is this: how to start remote actors in scala, but it seems much more inconvenient than I'd think it would be.

我有12台机器要工作.我想要一些类似的东西:

I have a cluster of 12 machines to work on. I would like to something along the lines of:

val system = ActorSystem("DistributedSystem", ConfigFactor.load.getConfig("distsys"))
val master = system.actorOf(Props(new Master(...)), "master")

然后在母版内部,类似以下内容:

and then inside of the master, something along the lines of:

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")
    }
}

似乎这将是一个合理的常见用例.是否有我缺少的东西,或者有什么好方法(就我的配置而言,还是我真正需要多少个ActorSystem而言)?我现在正在努力综合一个好的解决方案.

It seems like this would be a reasonably common use case. Is there something I'm missing, or is there a good way to do this (in terms of what my configuration should look like, or how many ActorSystems I really need)? I'm just struggling to synthesize a good solution right now.

推荐答案

我认为您想做的就是将一组actor部署到一组远程节点,然后将它们放置在本地路由器后面并传递消息到路由器,并让其将工作分配到远程节点.为此,您可以尝试执行以下操作:

I think what it sounds like you want to do is deploy a set of actors to a set of remote nodes and then sit them behind a local router and pass messages to the router and let it farm the work out to the remote nodes. To do that, you could try something like this:

val addresses = for(i <- 1 until 12) 
  yield AddressFromURIString(s"akka://RemoteSys@192.168.1.$i:2553")

val routerRemote = system.actorOf(Props[RemoteChild].withRouter(
  RemoteRouterConfig(RoundRobinRouter(12), addresses)))

这假设您在名为RemoteSysActorSystem的那些节点上运行了Akka,并且正在使用为端口2553配置的远程处理.当您向该routerRemote引用发送消息时,它将进行循环路由跨您的12个工作节点的消息.

This assumes that you have Akka running on those nodes with an ActorSystem called RemoteSys and it's using remoting configured for port 2553. When you send a message to that routerRemote ref, it will now round-robin route the messages across your 12 worker nodes.

这篇关于无需新的ActorSystem即可远程创建Akka actor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆