I used a reference for my implementation.
//https://doc.akka.io/docs/akka-management/current/bootstrap/local-config.html
Discovery Method: Configuration
I want to use with the same hostname and different ports for cluster endpoints as mentioned in below conf file
Please find below conf file
When I start the first node, it is forming the cluster, When I start the second node it is forming its own cluster instead of joining existing cluster.
In the end, I don’t want to manually configure seed nodes, I want to have dynamic cluster formation based upon whichever node I start first.
Please help how to fix it.
akka {
actor {
provider = "cluster"
allow-java-serialization = on
}
remote {
maximum-payload-bytes = 10000000 bytes
netty.tcp {
message-frame-size = 10000000b
send-buffer-size = 10000000b
receive-buffer-size = 10000000b
maximum-frame-size = 10000000b
}
}
cluster {
auto-down-unreachable-after = 10s #Not required in general.
jmx.multi-beans-in-same-jvm = on
jmx.multi-mbeans-in-same-jvm = on
}
}
#coorindated-shutdown
#akka.cluster.shutdown-after-unsuccessful-join-seed-nodes = 30s
#akka.coordinated-shutdown.exit-jvm = on
#coorindated-shutdown
#discovery
akka.discovery {
config.services = {
local-cluster = {
endpoints = [
{
host = "192.168.0.6"
port = 8560
},
{
host = "192.168.0.6"
port = 8561
}
]
}
}
}
#discovery
#health
akka.management.health-checks {
readiness-path = "health/ready"
liveness-path = "health/alive"
}
#health
akka.management.http {
route-providers-read-only = false
port = 8561
}
#bootstrap
akka.management {
cluster.bootstrap {
contact-point-discovery {
service-name = "local-cluster"
discovery-method = config
required-contact-point-nr = 1
}
}
}
#bootstrap
Java code
final Config config =
ConfigFactory.parseString("akka.remote.artery.canonical.hostname=192.168.0.6 \n"
+ "akka.management.http.hostname = 192.168.0.6 \n"
+ "akka.remote.artery.canonical.port=" + configuration.getPort()
)
.withFallback(ConfigFactory.parseString("akka.cluster.roles = ["+ROLE_PRODUCER+"]"))
.withFallback(ConfigFactory.load("communication.conf"));
system = ActorSystem.create(configuration.getActorSystem(), config);
producer = system.actorOf(
Props.create(ProducerActor.class , consumerQueue , consumers, configuration, commConfig), AkkaConstants.PRODUCER_ACTOR );
AkkaManagement.get(system).start();
ClusterBootstrap.get(system).start();
cluster = Cluster.get(system);