Configure Akka Router from Java configuration file

Just started exploring the possibilities of akka. I am trying to run a program that uses akka router based on sequential hashing.

My environment: Java 7 update 67, version akka-actor_2.10 2.3.7.

My configuration file:

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);
        }
    }
}

Startup fails with the following exception:

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

I wrote the code following this. Please advice.

+4
source share
1 answer

The minimum configuration required to initialize the router is consistent-hashing-groupas follows:

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

You used the wrong tag deployement- the correct onedeployment

+1
source

All Articles