Search code examples
gomicroservicesconsulservice-discovery

Where should i store the endpoint of the service registry server?


I'm learning about microservices recently. I tried using consul for service discovery. I wonder if I deploy the consul server, so where should i store endpoint of that server? Is it good to hard code in env variable of each services?


Solution

  • All of the 3 following options are supported in the following precedence order:

    1. Command line arguments
    2. Environment Variables
    3. Configuration files

    For the Linux Configuration File Option

    Create

    /etc/consul.d/config.json

    The key is start_join with value of the IP of Consul server e.g.,

    "start_join": [ "10.128.0.2" ]
    

    For a cluster solution of more than one Consul instances:

    "start_join": [ "10.128.0.2", "10.128.0.3" ]
    

    The default server port is 8300 but you may override with the ports object offering multiple ports to override e.g.,

    "ports": {
       "server": 8300
    }
    

    For a full reference of the available options, you may check the Consul Documentation, and all the available ports options