2016-11-04 51 views
0

當使用配置文件配置羣集路由:配置阿卡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呼叫集羣(只有本地的

如何配置正確的路由

回答

1

嘗試使用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