[英]How to create actor props with Router in Akka 2.5
in Akka 2.0 we used to have 在Akka 2.0中,我们曾经拥有
List<String> routeePaths = actorRefs.stream()
.map(e -> e.path().toString())
.collect(toList());
Props routerProps = Props.empty().withRouter(new BroadcastRouter(routeePaths));
But in Akka 2.5, BroadcastRouter and some other old Routers are not there any more. 但是在Akka 2.5中,不再提供BroadcastRouter和其他一些旧路由器。 Whats the proper way to add those routing behavior to actors.
将这些路由行为添加到参与者的正确方法是什么?
Akka 2.5 has BroadcastRoutingLogic
. Akka 2.5具有
BroadcastRoutingLogic
。 The examples below are from the documentation : 以下示例来自文档 :
Router router;
{
List<Routee> routees = new ArrayList<Routee>();
for (int i = 0; i < 5; i++) {
ActorRef r = getContext().actorOf(Props.create(Worker.class));
getContext().watch(r);
routees.add(new ActorRefRoutee(r));
}
router = new Router(new BroadcastRoutingLogic(), routees);
}
You can also use a BroadcastPool
or BroadcastGroup
: 您也可以使用
BroadcastPool
或BroadcastGroup
:
BroadcastPool
defined in configuration: 在配置中定义的
BroadcastPool
:
akka.actor.deployment {
/parent/router13 {
router = broadcast-pool
nr-of-instances = 5
}
}
ActorRef router13 = getContext().actorOf(FromConfig.getInstance().props(Props.create(Worker.class)), "router13");
BroadcastPool
defined in code: 在代码中定义的
BroadcastPool
:
ActorRef router14 = getContext().actorOf(new BroadcastPool(5).props(Props.create(Worker.class)), "router14");
BroadcastGroup
defined in configuration: 在配置中定义的
BroadcastGroup
:
akka.actor.deployment {
/parent/router15 {
router = broadcast-group
routees.paths = ["/user/workers/w1", "/user/workers/w2", "/use/workers/w3"]
}
}
ActorRef router15 = getContext().actorOf(FromConfig.getInstance().props(), "router15");
BroadcastGroup
defined in code: 代码中定义的
BroadcastGroup
:
List<String> paths = Arrays.asList("/user/workers/w1", "/user/workers/w2", "/user/workers/w3");
ActorRef router16 = getContext().actorOf(new BroadcastGroup(paths).props(), "router16");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.