How to make a client for multiple hosts

first, i build the consul cluster on my three server machine, which have three consul server and three consul client.

And i try to use for my golang code to connect consul cluster.

but it seems that the config param of <api.NewClient> function can only fill the string type Address, so that i can’t fill my three hosts

how should i config correctly ?
thanks !

Hi @linsijia1002,

Normally API clients just make a connection to a single Consul agent for all operations.

Is there a particular reason your application needs to communicate with multiple Consul agents?

hi @blake ,
yes , because the high available.
When the machine which is connected is down, it means the application is lose connection with the consul cluster.
Normally like redis cluster, or kafka cluster , client application fill multiple hosts to insure the high available.
So i want to know what should i do in consul cluster

In this case, you should run multiple instances of your application on each server that is running a Consul agent. The application should register itself into the Consul catalog by communicating with the Consul agent running on the same machine.

When other services query the catalog ( for the service name, Consul will respond with the IP addresses of each registered, healthy service instance.

Ok,i get you mean,i will try. thank you.
By the way, in your plan, is HTTP API better or DNS more recommended ?
I usually use the HTTP API.
Thank you.

Its really a matter of preference, and what your requirements are. The HTTP interface offers a bit more flexibility in terms of filtering and provides more information in its responses compared to what is in a DNS response.

If the HTTP API works well for your needs then you should continue to use it. :slight_smile: