akka.netakka-cluster

Akka.Management DiscoveryMethod.Config


Using Akka.Management it's possible to create a cluster without using seeds nodes. I'm developing a service by using "Akka Cluster" as my main toolkit and I'm using "Akka Cluster Bootstrap" via "discovery from config" to bootstrap it:

                    case DiscoveryMethod.Config:
                    b = b
                        .WithConfigDiscovery(options =>
                        {
                            options.Services.Add(new Service
                            {
                                Name = clusterConfig.ManagementOptions.ServiceName,
                                Endpoints = new[]
                                {
                                    $"{clusterConfig.ManagementOptions.Hostname}:{clusterConfig.ManagementOptions.Port}",
                                }
                            });
                        });
                 break;

Running the first node, the cluster is formed and the node become the leader. What is not clear is how to make another node (the second one) join the cluster. If I use the same configuration with a second node, it creates a new cluster like the first one. I mean the second node does not join the cluster of the first node, but creates a new cluster identical to the first one. Obviously the two node are on the same network and use the same ActorSystemName. The question is: how to make join the cluster to other nodes using Akka.Management and DiscoveryMethod.Config?


Solution

  • You need to provide the same network address endpoint array for both actor system, usually by hard-coding the value of the first node, or the values for both actor system. Note that these network address is not arbitrary, they have to match the host name and the management port set up inside the configurations.

    case DiscoveryMethod.Config:
    b
    .WithConfigDiscovery(options =>
    {
        options.Services.Add(new Service
        {
            Name = clusterConfig.ManagementOptions.ServiceName,
            Endpoints = new[]
            {
                $"localhost:10000",
                $"localhost:10001",
            }
        });
    });