How can i connect to cluster when master node changed?

Hi,
I have a cluster with three nodes on docker.
MasterNode: 0.0.0.0:9200, Node2: 0.0.0.0:9201, Node3: 0.0.0.0:9202

I use Nest in .NetCore Application. and i connect to cluster with http://:9200/
and this connection works as well.
But when master node fails , connection to :9200 also fails!!!
What is the best approach for this situation?

I think you can define the 3 nodes in the client so any of the nodes will be used.

You can use a SniffingConnectionPool and seed it with the three nodes:

var uris = Enumerable.Range(9200, 3)
    .Select(port => new Uri($"http://0.0.0.0:{port}"));

var pool = new SniffingConnectionPool(uris);
var client = new ElasticClient(new ConnectionSettings(pool));

A sniffing connection pool will periodically sniff the cluster to find the nodes in the cluster. Sniffing uses the publish_address returned for each node, or the first bound_address if there's no publish_address, so ensure that the address returned for each node can be reached by the client. This can be controlled with HTTP or network settings.

2 Likes

As a personal preference I'd generally recommend starting with the StaticConnectionPool and moving to the SniffingConnectionPool later, and then only if you need the sniffing functionality. Many clusters don't need sniffing, or they have alternative mechanisms for finding the client nodes (e.g. DNS or a loadbalancer). Conversely we often see confusion around getting the publish_address right, particularly in today's world of Docker containers and their confusingly inhomogeneous networks. By starting with the StaticConnectionPool you can avoid that confusion until it's absolutely necessary.

2 Likes

Thanks :+1:
@forloop
@DavidTurner

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.