DOC: Props.empty.withRouter, see #3464
This commit is contained in:
parent
1cca2b85e3
commit
7c3f6c21d8
5 changed files with 13 additions and 7 deletions
|
|
@ -29,7 +29,7 @@ object RoutingProgrammaticallyExample extends App {
|
||||||
val actor2 = system.actorOf(Props[ExampleActor1])
|
val actor2 = system.actorOf(Props[ExampleActor1])
|
||||||
val actor3 = system.actorOf(Props[ExampleActor1])
|
val actor3 = system.actorOf(Props[ExampleActor1])
|
||||||
val routees = Vector[ActorRef](actor1, actor2, actor3)
|
val routees = Vector[ActorRef](actor1, actor2, actor3)
|
||||||
val router2 = system.actorOf(Props().withRouter(
|
val router2 = system.actorOf(Props.empty.withRouter(
|
||||||
RoundRobinRouter(routees = routees)))
|
RoundRobinRouter(routees = routees)))
|
||||||
//#programmaticRoutingRoutees
|
//#programmaticRoutingRoutees
|
||||||
1 to 6 foreach { i ⇒ router2 ! Message1(i) }
|
1 to 6 foreach { i ⇒ router2 ! Message1(i) }
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ public class FactorialFrontend extends UntypedActor {
|
||||||
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||||
|
|
||||||
ActorRef backend = getContext().actorOf(
|
ActorRef backend = getContext().actorOf(
|
||||||
Props.create(FactorialBackend.class).withRouter(FromConfig.getInstance()),
|
Props.empty().withRouter(FromConfig.getInstance()),
|
||||||
"factorialBackendRouter");
|
"factorialBackendRouter");
|
||||||
|
|
||||||
public FactorialFrontend(int upToN, boolean repeat) {
|
public FactorialFrontend(int upToN, boolean repeat) {
|
||||||
|
|
@ -66,7 +66,7 @@ abstract class FactorialFrontend2 extends UntypedActor {
|
||||||
boolean allowLocalRoutees = true;
|
boolean allowLocalRoutees = true;
|
||||||
String useRole = "backend";
|
String useRole = "backend";
|
||||||
ActorRef backend = getContext().actorOf(
|
ActorRef backend = getContext().actorOf(
|
||||||
Props.create(FactorialBackend.class).withRouter(new ClusterRouterConfig(
|
Props.empty().withRouter(new ClusterRouterConfig(
|
||||||
new AdaptiveLoadBalancingRouter(HeapMetricsSelector.getInstance(), 0),
|
new AdaptiveLoadBalancingRouter(HeapMetricsSelector.getInstance(), 0),
|
||||||
new ClusterRouterSettings(
|
new ClusterRouterSettings(
|
||||||
totalInstances, routeesPath, allowLocalRoutees, useRole))),
|
totalInstances, routeesPath, allowLocalRoutees, useRole))),
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@ import akka.routing.FromConfig;
|
||||||
//#service
|
//#service
|
||||||
public class StatsService extends UntypedActor {
|
public class StatsService extends UntypedActor {
|
||||||
|
|
||||||
|
// This router is used both with lookup and deploy of routees. If you
|
||||||
|
// have a router with only lookup of routees you can use Props.empty()
|
||||||
|
// instead of Props.create(StatsWorker.class).
|
||||||
ActorRef workerRouter = getContext().actorOf(
|
ActorRef workerRouter = getContext().actorOf(
|
||||||
Props.create(StatsWorker.class).withRouter(FromConfig.getInstance()),
|
Props.create(StatsWorker.class).withRouter(FromConfig.getInstance()),
|
||||||
"workerRouter");
|
"workerRouter");
|
||||||
|
|
@ -56,7 +59,7 @@ abstract class StatsService2 extends UntypedActor {
|
||||||
boolean allowLocalRoutees = true;
|
boolean allowLocalRoutees = true;
|
||||||
String useRole = "compute";
|
String useRole = "compute";
|
||||||
ActorRef workerRouter = getContext().actorOf(
|
ActorRef workerRouter = getContext().actorOf(
|
||||||
Props.create(StatsWorker.class).withRouter(new ClusterRouterConfig(
|
Props.empty().withRouter(new ClusterRouterConfig(
|
||||||
new ConsistentHashingRouter(0), new ClusterRouterSettings(
|
new ConsistentHashingRouter(0), new ClusterRouterSettings(
|
||||||
totalInstances, routeesPath, allowLocalRoutees, useRole))),
|
totalInstances, routeesPath, allowLocalRoutees, useRole))),
|
||||||
"workerRouter2");
|
"workerRouter2");
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ object FactorialFrontend {
|
||||||
//#frontend
|
//#frontend
|
||||||
class FactorialFrontend(upToN: Int, repeat: Boolean) extends Actor with ActorLogging {
|
class FactorialFrontend(upToN: Int, repeat: Boolean) extends Actor with ActorLogging {
|
||||||
|
|
||||||
val backend = context.actorOf(Props[FactorialBackend].withRouter(FromConfig),
|
val backend = context.actorOf(Props.empty.withRouter(FromConfig),
|
||||||
name = "factorialBackendRouter")
|
name = "factorialBackendRouter")
|
||||||
|
|
||||||
override def preStart(): Unit = sendJobs()
|
override def preStart(): Unit = sendJobs()
|
||||||
|
|
@ -146,7 +146,7 @@ abstract class FactorialFrontend2 extends Actor {
|
||||||
import akka.cluster.routing.AdaptiveLoadBalancingRouter
|
import akka.cluster.routing.AdaptiveLoadBalancingRouter
|
||||||
import akka.cluster.routing.HeapMetricsSelector
|
import akka.cluster.routing.HeapMetricsSelector
|
||||||
|
|
||||||
val backend = context.actorOf(Props[FactorialBackend].withRouter(
|
val backend = context.actorOf(Props.empty.withRouter(
|
||||||
ClusterRouterConfig(AdaptiveLoadBalancingRouter(HeapMetricsSelector),
|
ClusterRouterConfig(AdaptiveLoadBalancingRouter(HeapMetricsSelector),
|
||||||
ClusterRouterSettings(
|
ClusterRouterSettings(
|
||||||
totalInstances = 100, routeesPath = "/user/factorialBackend",
|
totalInstances = 100, routeesPath = "/user/factorialBackend",
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,9 @@ case class JobFailed(reason: String)
|
||||||
|
|
||||||
//#service
|
//#service
|
||||||
class StatsService extends Actor {
|
class StatsService extends Actor {
|
||||||
|
// This router is used both with lookup and deploy of routees. If you
|
||||||
|
// have a router with only lookup of routees you can use Props.empty
|
||||||
|
// instead of Props[StatsWorker.class].
|
||||||
val workerRouter = context.actorOf(Props[StatsWorker].withRouter(FromConfig),
|
val workerRouter = context.actorOf(Props[StatsWorker].withRouter(FromConfig),
|
||||||
name = "workerRouter")
|
name = "workerRouter")
|
||||||
|
|
||||||
|
|
@ -225,7 +228,7 @@ abstract class StatsService2 extends Actor {
|
||||||
import akka.cluster.routing.ClusterRouterSettings
|
import akka.cluster.routing.ClusterRouterSettings
|
||||||
import akka.routing.ConsistentHashingRouter
|
import akka.routing.ConsistentHashingRouter
|
||||||
|
|
||||||
val workerRouter = context.actorOf(Props[StatsWorker].withRouter(
|
val workerRouter = context.actorOf(Props.empty.withRouter(
|
||||||
ClusterRouterConfig(ConsistentHashingRouter(), ClusterRouterSettings(
|
ClusterRouterConfig(ConsistentHashingRouter(), ClusterRouterSettings(
|
||||||
totalInstances = 100, routeesPath = "/user/statsWorker",
|
totalInstances = 100, routeesPath = "/user/statsWorker",
|
||||||
allowLocalRoutees = true, useRole = Some("compute")))),
|
allowLocalRoutees = true, useRole = Some("compute")))),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue