GithubHelp home page GithubHelp logo

kurt-nj / consulex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from team-telnyx/consulex

0.0 1.0 0.0 18 KB

Elixir library for interacting with Consul on top of Tesla

License: Apache License 2.0

Elixir 100.00%

consulex's Introduction

Consul

Yet another Consul Client written in Elixir, this time on top of Tesla.

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 consulex to your list of dependencies in mix.exs:

def deps do
  [
    {:consulex, "~> 0.1"}
  ]
end

And then you need to pass which JSON interpreter you'll use. If that's Jason, then do:

# config/config.exs
config :consulex, json_codec: Jason

You can use Poison instead, by just substituting Jason by Poison in the above configuration. Other libraries might need a custom Consul.JsonCodec behaviour implementation.

Documentation is generated with ExDoc and published on HexDocs. Docs can be found at https://hexdocs.pm/consulex.

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.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.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.

Read YAML values from Consul KV

By default, Consulex will attempt to decode Consul KV values as JSON (using the JsonCodec of your choice). If you have YAML values, add an YAML decoder that implements the Consul.YamlCodec behaviour. YamlElixir is supported out of the box by setting it in your config:

# config/config.exs
config :consulex, yaml_codec: YamlElixir

consulex's People

Contributors

balena avatar kianmeng avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.