GithubHelp home page GithubHelp logo

isabella232 / etcd-registry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from e-conomic/etcd-registry

0.0 0.0 0.0 36 KB

Service registry for Node.js on top of etcd

License: MIT License

JavaScript 100.00%

etcd-registry's Introduction

Archived

Tech Leads: Repository archived due to inactivity in more than 6 months. Please remember to add a CODEOWNERS file to the root of the repository when unarchiving.

etcd-registry

Service registry for Node.js on top of etcd

npm install etcd-registry

To install the command line tool

npm install -g etcd-registry
etcd-registry help

Usage

var registry = require('etcd-registry');

// Pass the nodes in your cluster in a connection string
var services = registry('127.0.0.1:4001,127.0.0.1:4002,127.0.0.1:4003');

// Join the registry
services.join('my-service-name', {port:8080});

// Wait a bit and do a lookup
services.lookup('my-service-name', function(err, service) {
	console.log('Found the following service:');
	console.log(service);
});

Running the above example will produce the following output

Found the following service:
{
	name: 'my-service-name',
	port: 8080,
	hostname: '192.168.1.10',
	host: '192.168.1.10:8080',
	url: 'http://192.168.1.10:8080'
}

Full api

  • services = registry(connection-string) Create a new registry client
  • services.join(name, service, [cb]) Join the registry with a new service
  • services.leave([name], [cb]) Leave the registry. Omit the name to remove local services
  • services.lookup(name, cb) Lookup a single service
  • services.list([name], cb) List all services as an array. Omit the name to list all services

Connection string

The connection has the following format

protocol://host1,host2,host3,.../namespace?options

The protocol can be https or http and defaults to http. If you set a namespace all keys will be prefixed with the value. If you do not specify a port in the hosts 4001 will be used (default etcd port).

Services

Services are just JSON documents. etcd-registry will add a default hostname and a couple of other properties. An example of a service document could be:

{
	name: 'my-service',
	port: 8080,
	hostname: '192.168.1.10',       // added by etcd-registry
	host: '192.168.1.10:8080',      // added by etcd-registry
	url: 'http://192.168.1.10:8080' // added by etcd-registry
}

These documents are saved in etcd with a TTL of 10s. Every 5s etcd-registry will send a heartbeat for each service to the registry which resets the expiration counter. If possible you should call services.leave() before exiting your service process. Otherwise your service will be garbage collected after (at most) 10s

Fault tolerance

If a operation fails etcd-registry will try another node in the cluster until it has tried everyone. Every once in a while etcd-registry will ping your cluster to see if new machines has joined and update the connection string

License

MIT

etcd-registry's People

Contributors

henrikchr avatar kapetan avatar mafintosh 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.