Created
October 4, 2018 17:30
-
-
Save johanandren/78019fafaf0cc39aec1f42c721b74a9c to your computer and use it in GitHub Desktop.
Three node Akka cluster in one JVM with minimal fuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.ActorSystem | |
import akka.cluster.Cluster | |
import com.typesafe.config.ConfigFactory | |
object ProgrammaticJoin extends App { | |
val commonConfig = ConfigFactory.parseString( | |
""" | |
akka { | |
actor.provider = cluster | |
remote.artery.enabled = true | |
remote.artery.canonical.hostname = 127.0.0.1 | |
remote.artery.canonical.port = 0 | |
cluster.jmx.multi-mbeans-in-same-jvm = on | |
} | |
""") | |
val node1 = ActorSystem("cluster", commonConfig) | |
val node2 = ActorSystem("cluster", commonConfig) | |
val node3 = ActorSystem("cluster", commonConfig) | |
// joins itself to form cluster | |
val node1Cluster = Cluster(node1) | |
node1Cluster.join(node1Cluster.selfAddress) | |
// joins the cluster through the one node in the cluster | |
val node2Cluster = Cluster(node2) | |
node2Cluster.join(node1Cluster.selfAddress) | |
// subsequent nodes can join through any node that is already in the cluster | |
val node3Cluster = Cluster(node3) | |
node3Cluster.join(node2Cluster.selfAddress) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment