Cluster discovery (dynamic) using seeds

Suppose I know which actors are part of the cluster and that this information is dynamic. Then I would do something like this to call all of them as seed nodes and join them.

val seedNodes: List[Address] =
  List("akka://ClusterSystem@", "akka://ClusterSystem@").map(AddressFromURIString.parse)
Cluster(system).manager ! JoinSeedNodes(seedNodes)

When a node leaves, it might not do an graceful exit. In that case, Akka will figure out. When it comes back, it will join seed nodes (including itself). Is that the correct approach? Or is it better to specify itself and another node (and let the system figure out all members by itself?)

I’d recommend that you read the documentation for joining one more time, and if it’s still unclear I’d be happy to try to clarify.

Thanks @patriknw. So, I’d use " Joining programmatically to seed nodes" section. It states "When joining to seed nodes you should not include the node itself, except for the node that is supposed to be the first seed node bootstrapping the cluster. " Suppose there are two nodes, A and B. A= akka://ClusterSystem@ and B=akka://ClusterSystem@ Lets say “A” is supposed to be the first node, it will do JoinSeedNodes(List(“akka://ClusterSystem@”)) and “B” will do JoinSeedNodes(List(“akka://ClusterSystem@”)). I’d have to programmatically ensure this? i.e., I cannot have A join JoinSeedNodes(List(“akka://ClusterSystem@”)) and B join JoinSeedNodes(List(“akka://ClusterSystem@”))? Also, the other case, where A and B are concurrent and do not know who should bootstrap, they cannot do A joins A and B joins B (because they didn’t know whom the first person should be?) Thanks

As long as you have the same node as the first element in the list, on all nodes, then it’s safe because only that first node will join itself. You should always have more than one in the list for redundancy and so that the first will join existing cluster if it’s restarted.

On node A: [A, B, C]
On node B: [A, B, C]
On node C: [A, B, C]

Or alternatively
On node A: [A, B, C]
On node B: [A, C]
On node C: [A, B]

1 Like