I want to setup the Akka Cluster using Spring Framework. I have below configuration
akka {
loglevel = debug
actor {
provider = cluster
serialization-bindings {
"sample.cluster.CborSerializable" = jackson-cbor
}
}
remote {
artery {
canonical.hostname = "gardenint01.mahek.com"
canonical.port = 2551
}
}
cluster {
seed-nodes = [
"akka://ClusterSystem@gardenint01.mahek.com:2551",
"akka://ClusterSystem@gardenint02.mahek.com:2551"
]
roles = ["seed","compute"]
role { seed.min-nr-of-members = 2 }
}
}
I am using this configuration in below code to setup Akka Cluster System initializing through SpringExtension
@Bean(name="ComputeClusterSystem")
@Scope("prototype")
public ActorSystem akkaGridClusterSystem() {
final Config config = ConfigFactory.parseResources(compute-cluster.conf").
withFallback(ConfigFactory.parseString(configString)).
withFallback(ConfigFactory.systemProperties()).
withFallback(ConfigFactory.systemEnvironment()).
resolve();
ActorSystem<Void> system = ActorSystem.create(RootBehavior.create(), "EngineComputeClusterSystem", config);
// initialize the application context in the Akka Spring Extension
SpringExtension.SpringExtProvider.get(system).initialize(applicationContext);
return system;
}
In Below code,I am registering the Service and worker routers and creating worker actors.
private static class RootBehavior {
static Behavior<Void> create() {
return Behaviors.setup(context -> {
Cluster cluster = Cluster.get(context.getSystem());
boolean preferLocalRoutees=true;
ActorRef<EngineComputeWorker.RunRequestCommand> workerRouter = context.spawn(Routers.group(RUN_WORKER_KEY).withRoundRobinRouting(preferLocalRoutees), "WorkerRouter");
ActorRef<ClusterComplRunService.Command> service = context.spawn(ClusterRunService.create(workerRouter), "RunService");
context.getSystem().receptionist().tell(Receptionist.register(RUN_SERVICE_KEY, service.narrow()));
// on every compute node there is one service instance that delegates to N local workers
final int numberOfWorkers = context.getSystem().settings().config().getInt("run-service.workers-per-node");
context.getLog().info("Starting {} workers", numberOfWorkers);
for (int i = 0; i < numberOfWorkers; i++) {
context.getLog().info("Starting Computer Worker {} ","ComputeWorker" + i);
ActorRef<EngineComputeWorker.Command> worker = context.spawn(EngineComputeWorker.create(), "ComputeWorker" + i);
context.getLog().info("Started Computer Worker {} ","ComputeWorker" + i);
context.getSystem().receptionist().tell(Receptionist.register(RUN_WORKER_KEY, worker.narrow()));
}
return Behaviors.empty();
});
}
}
So question is that Do I need to create number of worker actors as I did in the code or Akka configuration automatically create child worker actors dynamically. Also, Is above congfiguration is correct way to initialize the actor systems ?
I implemented using the Akka cluster example code but example starts the “compute” and “client” actor manually in main application with argument but I am looking to implement in the webapplication so at startup time, actor system should initialize and Service and worker actors should be created. Am I missing anything ?