ExConsulUrl
Simple client to retrieve the IP and port that a service is running on from HashiCorp’s Consul.
Installation
If available in Hex, the package can be installed as:
-
Add
ex_consul_urlto your list of dependencies inmix.exs:
def deps do
[{:ex_consul_url, "~> 0.1.0"}]
end-
Ensure
ex_consul_urlis started before your application:
def application do
[applications: [:ex_consul_url]]
endUsage
Given a service and it’s Consul tags, retrieve the IP and port it runs on. For example:
iex> ExConsulUrl.url_for("consul://production.my-service")
"http://127.0.0.1:8080"
iex> ExConsulUrl.url_for("my-service", "production")
"127.0.0.1:8080"
iex> ExConsulUrl.url_for!("service-not-there", "production")
# Throws ServiceNotFound errorNote: If the service and tags map to multiple IP/port pairs, the first one is always chosen.