Implementing service discovery using Spring Cloud Consul
In the previous recipe, we orchestrated a consul agent in development. In this recipe, we will be using that consul agent to implement service discovery for the geolocation microservice. When we did something similar using Zookeeper, there was lot of code involved to connect to Zookeeper, identify the IP, identify the port, and finally register the service. We performed these steps using the curator API, which made our life easier. But fortunately, you don't have to do all this for consul. Spring Cloud has a library for consul, which automatically registers the service with the host and port information. All we have to provide is a couple of properties. Let's take a look at how to do that now.
Getting ready
In order to register the geolocation service in consul, we first have to make sure that the consul agent is up and running. If you don't have an agent running, start it using
docker-compose
.Go ahead and make sure consul was properly...