Gem Version Build Status Code Climate

A HTTP Ruby API for Consul

Diplomacy Boad Game


What's Diplomat for?

Diplomat allows any ruby application to interact with Consul's distributed key value store, and also receive information about services currently available in the Consol cluster.

Does it work in rails?

Yup! In fact, we're using it in all of our rails production apps instead of any previous case where it'd be right to use environment variables according to 12Factor configuration principals. This gives us the ability to scale up without making any changes to the actual project codebase, and to move applications around the cluster with ease.

Here's what a production database.yml file might look like:

<% if Rails.env.production? %>
  adapter:            postgresql
  encoding:           unicode
  host:               <%= Diplomat::Service.get('postgres').Address %>
  database:           <%= Diplomat.get('project/db/name') %>
  pool:               5
  username:           <%= Diplomat.get('project/db/user') %>
  password:           <%= Diplomat.get('project/db/pass') %>
  port:               <%= Diplomat::Service.get('postgres').ServicePort %>
<% end %>

Why would I use Consol over ZooKeeper, Doozerd, etcd, Nagios, Sensu, SmartStack, SkyDNS, Chef, Puppet, Ansible, etc?

Read up what makes Consul different here

How do I install Consul?

See here. I managed to roll it out on my production machines with the help of Ansible in one working day.


The most up to date place to read about the API is here.

Here's a few examples of how diplomat works:

Key Values


Getting the value of a key in the key-value store is as simple as using one of the following:

foo = Diplomat.get('foo')
# => "bar"


Setting the value of a key is just as easy:

foo = Diplomat.put('foo', 'bar')
# => "bar"



Looking up a service is easy as pie:

foo_service = Diplomat::Service.get('foo')
# => #<OpenStruct Node="hotel", Address="", ServiceID="hotel_postgres", ServiceName="hotel_postgres", ServiceTags=["postgres"], ServicePort=5432> 


  • Deleting Keys
  • Listing available Services, PUTting and DELETEing services
  • Health
  • Members
  • Status


Photo Copyright "merlinmann". All rights reserved.