引用路由器的路由 [英] Routees referring to Router

查看:120
本文介绍了引用路由器的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用下面的代码(来自 http:// doc。 akka.io/docs/akka/2.0/scala/routing.html ),路由如何引用/与 router2通信(不使用 sender()),因为 context.parent 不起作用?

If I use the code below (from http://doc.akka.io/docs/akka/2.0/scala/routing.html), how do the routees refer to/communicate with router2 (without using sender()), as the context.parent does not work?

val actor1 = system.actorOf(Props[ExampleActor1])
val actor2 = system.actorOf(Props[ExampleActor1])
val actor3 = system.actorOf(Props[ExampleActor1])
val routees = Vector[ActorRef](actor1, actor2, actor3)
val router2 = system.actorOf(Props[ExampleActor1].withRouter(
RoundRobinRouter(routees = routees)))


推荐答案

正如您目前所写,它们还不能。您必须将路由器的 ActorRef 明确传递给路由。

As you've currently written it, they can't. You'll have to pass the router's ActorRef to the routees explicitly.

另一个选择是让路由器创建其路由,因为路由的 context.parent 将引用路由器。

The other option is the let the router create its routees as then the routees' context.parent will refer to the router.

这篇关于引用路由器的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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