GithubHelp home page GithubHelp logo

instructure_registrar's Introduction

InstructureRegistrar

InstructureRegistrar is a Ruby library for registering and retrieving service information from a central etcd service registry.

Installation

Add this line to your application's Gemfile:

gem 'instructure_registrar'

And then execute:

$ bundle

Usage

Make sure that the following environment variables are set with the appropriate information for your local etcd instance:

REGISTRY_HOST
REGISTRY_PORT

Integrating with a service

In your service's project folder, create a configuration file with the following contents:

#/config/initializers/instructure_registrar.rb
require 'instructure_registrar'
require 'dotenv'
Dotenv.load

InstructureRegistrar.configure do |config|
  config.registry_host = ENV['REGISTRY_HOST']# || "http://instructure-etcd.docker"
  config.registry_port = ENV['REGISTRY_PORT']# || 12379
  config.service_name  = "sample_service_3"
  config.service_config = {
    host: "http://someservice.docker",
    token: 'foo',
    option: 'bar'}
end

if ENV['RAILS_ENV'] == "development"
  InstructureRegistrar.register
  at_exit { InstructureRegistrar.unregister }
end

Looking up a service

Note that your client application will need a config file similar to that in the section above, but unless you plan on registering your app as a service your config file will be simpler:

#/config/initializers/instructure_registrar.rb
require 'dotenv'
Dotenv.load
require 'instructure_registrar'

InstructureRegistrar.configure do |config|
  config.registry_host = ENV.fetch('REGISTRY_HOST') || "http://instructure-etcd.docker"
  config.registry_port = ENV.fetch("REGISTRY_PORT") || 12379
end

Then, to fetch connection information for a given service:

require 'instructure_registrar'
@some_service_url = InstructureRegistrar.get_service('some_service_name')

This will return all keys and values associated with the service.

instructure_registrar's People

Contributors

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