Using service discovery with Consul
When using the microservice approach to applications, you end up with a lot of servers listening on a variety of IPs, domains, and ports. These IP addresses will vary by environment (staging versus production), and it can be tricky to keep them static for configuration between services. You also want to know when a machine or service is down or unreachable due to a network partition. Consul is a tool that provides a lot of functionality, but we'll explore registering services with Consul and querying them from our other services.
Getting ready
Configure your environment according to these steps:
- Download and install Go on your operating system from https://golang.org/doc/install and https://golang.org/doc/installconfigure your
GOPATH
environment variable. - Open a terminal/console application.
- Navigate to
GOPATH/src
and create a project directory, for example,$GOPATH/src/github.com/yourusername/customrepo
. All code will be run and modified from this directory...