Skip to content

Elixir library for interacting with Consul on top of Tesla

License

Notifications You must be signed in to change notification settings

simplifi/exconsulex

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExConsulEx

A Consul Client written in Elixir using Tesla.

This project was forked from 'Consulex'

At the time of writing, it doesn't support all APIs, just KV/Catalog/Health and read-only APIs. On the other hand, it implements a Tesla.Middleware.ConsulWatch to ease doing blocking queries to Consul.

Installation

The package can be installed by adding exconsulex to your list of dependencies in mix.exs:

def deps do
  [
    {:exconsulex, "~> 0.2"}
  ]
end

The JSON interpreter used by default is Jason.

This can be overriden with another implementation, such as Poison with the following config. then do:

# config/config.exs
config :exconsulex, json_codec: Poison

How to use

For simple polling requests, just create a Consul connection and pass it to a Consul.Api module:

connection = Consul.Connection.new("http://consul:8500")
Consul.Api.V1.Health.list_nodes(connection, "my_service", passing: true)

In order to make blocking queries, use the option :wait:

connection = Consul.Connection.new("http://consul:8500", wait: 60_000)
Consul.Api.V1.Health.list_nodes(connection, "my_service", passing: true)

In this case, the first execution will return immediately, while the next ones will wait up to 60 seconds to finalize. The time passed in the :wait argument is in milliseconds.

About

Elixir library for interacting with Consul on top of Tesla

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 100.0%