无需新的ActorSystem即可远程创建Akka actor

编程入门 行业动态 更新时间:2024-10-08 01:22:56
本文介绍了无需新的ActorSystem即可远程创建Akka actor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经浏览过文档多次( doc.akka.io/docs/akka/2.1.4/scala/remoting.html ),并通过此处的示例( github/akka/akka/tree/master/akka-samples/akka-sample-remote )以及通过其他人,但我仍然不知道该怎么做我想做的事情.我找到的最接近的答案是:如何在Scala中启动远程参与者,但似乎比我想象的要麻烦得多.

I've been over the documentation several times now (doc.akka.io/docs/akka/2.1.4/scala/remoting.html) and through the example here (github/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)))

这假设您在名为RemoteSys的ActorSystem的那些节点上运行了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

本文发布于:2023-11-25 11:45:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629614.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ActorSystem   Akka   actor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!