【问题标题】:Configure Akka router from configuration file in Java从 Java 中的配置文件配置 Akka 路由器
【发布时间】:2014-12-01 20:01:53
【问题描述】:

刚开始了解 akka 功能。我正在尝试运行一个使用基于一致哈希的 akka 路由器的程序。

我的环境是:Java 7 update 67,akka-actor_2.10 version 2.3.7。

我的配置文件:

MyRouter{
    akka.actor.deployment{
        /exampleRouter {
            router = consistent-hashing-pool
            nr-of-instances = 5
        }
    }
}  

Main.java:

public class Main {

    public static void main(String... args){

        ActorSystem system = ActorSystem.create("ExampleRouter", ConfigFactory.load().getConfig("MyRouter"));
        ActorRef router = system.actorOf(Props.create(AcceptorActor.class).withRouter(new FromConfig()), "exampleRouter");

        for (int i = 0; i < 10; i++){
            router.tell(new RevisionContent("Hi", new Object()),  router);
            router.tell(new RevisionContent("Hello", new Object()),  router);
        }
    }
}

启动失败,出现以下异常:

Exception in thread "main" akka.ConfigurationException: configuration problem while creating [akka://ExampleRouter/user/exampleRouter] with router dispatcher [akka.actor.default-dispatcher] and mailbox [akka.actor.default-mailbox] and routee dispatcher [akka.actor.default-dispatcher] and mailbox [akka.actor.default-mailbox]
    at akka.actor.LocalActorRefProvider.actorOf(ActorRefProvider.scala:752)
    at akka.actor.dungeon.Children$class.makeChild(Children.scala:207)
    at akka.actor.dungeon.Children$class.attachChild(Children.scala:42)
    at akka.actor.ActorCell.attachChild(ActorCell.scala:369)
    at akka.actor.ActorSystemImpl.actorOf(ActorSystem.scala:553)
    at study.Main.main(Main.java:16)
Caused by: akka.ConfigurationException: Configuration missing for router [akka://ExampleRouter/user/exampleRouter] in 'akka.actor.deployment' section.
    at akka.routing.FromConfig.verifyConfig(RouterConfig.scala:297)
    at akka.routing.RoutedActorRef.<init>(RoutedActorRef.scala:40)
    at akka.actor.LocalActorRefProvider.actorOf(ActorRefProvider.scala:750)
    ... 5 more

我在example 之后编写了我的代码。请指教。

【问题讨论】:

  • FromConfig.getInstance() 代替 new FromConfig() 有帮助吗?
  • 没有。打印同样的错误。

标签: java akka


【解决方案1】:

初始化consistent-hashing-group路由器所需的最低配置如下:

MyRouter{
  akka {
    actor {
      deployment {
        /exampleRouter {
          router = consistent-hashing-group
        }
      }
    }
  }
}

您使用了错误的标签deployement - 正确的是deployment

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 2016-11-14
    • 2016-05-27
    • 2016-04-13
    相关资源
    最近更新 更多