Creating multiple clusters on single machine

akka-cluster
(Anilkumble) #1

Can I have multiple clusters in a single machine ?
As per my understanding ActorSystem name is cluster name - Am I correct ?

Below is the code which I used to create a cluster,

File1.java
Config config = ConfigFactory.parseString(“akka.remote.netty.tcp.port=”+port)
.withFallback(ConfigFactory.load());
Config config = ConfigFactory.load();
ActorSystem system = ActorSystem.create( “RunnerCluster” ,config);
ActorRef masterActor = system.actorOf(Props.create(MasterActor.class),“master-actor”);
ClusterClientReceptionist.get(system).registerService(masterActor);

So here RunnerCluster is my Actor System name and this is my cluster name as well
If I run the above code two times with different port then it will form a cluster. I want to create one more cluster with name of RunnerCluster2

So What should I supposed to do create one more cluster ?

(Patrik Nordwall) #2

You can have several clusters in the same machine (or even in the same JVM). The port for each ActorSystem in the same machine must be unique. The cluster is defined by what ActorSystems (nodes) that join each other.

There is a check when joining that the names of the ActorSystems are the same, i.e. all ActorSystems in the same cluster must have the same name. Useful for preventing test to join prod accidentilly, or similar.

You can read more about joining in the documentation.