How it works...
Consul provides a robust Go API library. It can feel daunting when first starting, but this recipe shows how you might approach wrapping it. Configuring Consul further is beyond the scope of this recipe, but this shows the basic for registering a service and querying for other services given a key and tag.
It would be possible using this to register new microservices at startup time, query for all dependent services, and deregister at shutdown. You might also want to cache this information so that you're not hitting Consul for every request, but this recipe provides the basic tools that you can expand upon. The Consul agent also makes these repeated requests fast and efficient (https://www.consul.io/intro/getting-started/agent.html ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access