Reputation: 12582
in Akka 2.0 we used to have
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. Whats the proper way to add those routing behavior to actors.
Upvotes: 0
Views: 561
Reputation: 19517
Akka 2.5 has 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
defined in configuration:
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:
ActorRef router14 = getContext().actorOf(new BroadcastPool(5).props(Props.create(Worker.class)), "router14");
BroadcastGroup
defined in configuration:
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:
List<String> paths = Arrays.asList("/user/workers/w1", "/user/workers/w2", "/user/workers/w3");
ActorRef router16 = getContext().actorOf(new BroadcastGroup(paths).props(), "router16");
Upvotes: 1