配置阿卡ClusterRouting编程

问题描述:

当使用配置文件配置群集路由:配置阿卡ClusterRouting编程

ActorRef actor = context().actorOf(// 
    FromConfig.getInstance().props(// 
    Props.create(MyRoutedActor.class)), // 
    "workerRouter"); 

我宁愿编程方式配置池,因为我想:

akka.actor.deployment { 
    /jobDispatcher/singleton/workerRouter { 
     router = round-robin-pool 
     nr-of-instances = 5 
     cluster { 
      enabled = on 
      max-number-of-instances-per-node = 1 
      allow-local-routees = on 
     } 
    } 
} 

我可以使用查找路由的工作人员隐藏我的用户的详细信息。

但是使用:

ActorRef actor = context().actorOf(new ClusterRouterPool(new RoundRobinPool(5), // 
    new ClusterRouterPoolSettings(100, 1, true, "")) // 
    .props(Props.create(MyRoutedActor.class)), 
    "workerRouter"); 

并不路线Routees呼叫集群(只有本地的

如何配置正确的路由

尝试使用ClusterRouterPool

Akka doc says says [http://doc.akka.io/docs/akka/2.4/scala/cluster-usage.html]

池 - 将路由创建为子actor并将其部署到远程节点上的路由器。每个路由器都有自己的routee实例。例如,如果在10节点群集中的3个节点上启动路由器,则如果路由器配置为每个节点使用一个实例,则总共将有30个路由。由不同路由器创建的路由不会在路由器之间共享。这种类型的路由器的用例的一个例子是协调作业并将实际工作委派给在集群中的其他节点上运行的路由的单个主设备。

的例子http://doc.akka.io/docs/akka/2.4/java/cluster-usage.html#Router_with_Pool_of_Remote_Deployed_Routees

akka.actor.deployment { 
    /statsService/singleton/workerRouter { 
     router = consistent-hashing-pool 
      cluster { 
      enabled = on 
      max-nr-of-instances-per-node = 3 
      allow-local-routees = on 
     use-role = compute 
     } 
    } 
} 

做编程方式(也是从阿卡文档)代码:

int totalInstances = 100; 
int maxInstancesPerNode = 3; 
boolean allowLocalRoutees = false; 
String useRole = "compute"; 
ActorRef workerRouter = getContext().actorOf(
    new ClusterRouterPool(new ConsistentHashingPool(0), 
     new ClusterRouterPoolSettings(totalInstances, maxInstancesPerNode, 
     allowLocalRoutees, useRole)).props(Props 
    .create(StatsWorker.class)), "workerRouter3"); 

我在斯卡拉的阿卡集群,这是我的代码:

val workerRouter = context.actorOf(
    ClusterRouterGroup(AdaptiveLoadBalancingGroup(MixMetricsSelector), ClusterRouterGroupSettings(//RoundRobinGroup(Nil) 
    totalInstances = 1000, routeesPaths = List("/user/worker"), 
    allowLocalRoutees = true, useRole = Some("workerRole"))).props(), 
name = "pool") 
+0

不知道到底出了什么问题l解决方案。然而你的似乎工作, – herzrasen