This package has been deprecated

Author message:

This module is deprecated, please use simple-service-registry instead

simple-orchestration-js

0.1.0 • Public • Published

simple-orchestration-js

This module is a wrapper around Etcd, designed to assist with the orchestration of distributed services and configuration.

Installation and Setup

To install, npm install simple-orchestration-js.

To use:

const SO = require('simple-orchestration-js')

const so = return new SO({ 
	url: <Host of Etcd instance>
})

Optional params

This module uses request under the hood so any request parameter can be passed in as part of the options.

If you are using Etcd via Compose and want to use the supplied SSL certificate you can do:

const SO = require('simple-orchestration-js')

const so = return new SOS({ 
	url: <Host of Etcd instance>,
	ca: fs.readFileSync("/path/to.cert.ca")
})

Alternatively, if you wish to ignore the SSL requirements, use strictSSL: false:

const SO = require('simple-orchestration-js')

const so = return new SOS({ 
	url: <Host of Etcd instance>,
	strictSSL: false
})

Methods

There are a number of methods to help with the orchestration of services and configuration.

.register( namespace, serviceName, serviceConfig, opts )

The .register() method will register a service in Etcd.

  • namespace is a string that defines a namespace for these services to be collected in (e.g. production, search, crm)
  • serviceName is a string that defines the name of the service
  • serviceConfig is a JSON object that defines the configuration needed to consume this service
  • opts is a JSON object that defines some options for the registration, such as a TTL.
const serviceConfig = {
  hostname: "http://search.example.com",
  api_key: "mylittlesecret"
}
so.register("production", "search-api", serviceConfig, { ttl: 30 })

The .register() method will register this service against Etcd every 10 seconds by default (or by the defined ttl). This means that once your app is stopped, the registration will expire within this time frame.

.service( namespace, serviceName )

The .service() method will attempt to discover a service by serviceName in a particular namespace.

This method returns an EventEmitter with events on:

  • set - when a service is registered (or re-registered)
  • expire - when a service registration expires
  • delete - when a service registration is deleted
so.service("production", "search-api")
.on("set", data => {
	// handle set event
})
.on("expire", data => {
	// handle expire event
})
.on("delete", data => {
	// handle delete event
})

.setEnv( namespace, envName, envValue, [callback] )

The .setEnv() method will set an environment parameter inside the provided namespace.

so.setEnv("production", "support-email", "support@example.com", (err, data) => {
	// handle optional callback
});

.getEnv( namespace, envName )

The .getEnv() method will attempt to discover environment parameters inside the provided namespace.

This method returns an EventEmitter with events on:

  • set - when a service is registered (or re-registered)
  • expire - when a service registration expires
  • delete - when a service registration is deleted
getEnv("production", "support-email")
.on("set", data => {
	// handle set event
})
.on("expire", data => {
	// handle expire event
})
.on("delete", data => {
	// handle delete event
})

Contributing

The projected is released under the Apache-2.0 license so forks, issues and pull requests are very welcome.

Package Sidebar

Install

npm i simple-orchestration-js

Weekly Downloads

0

Version

0.1.0

License

Apache-2.0

Last publish

Collaborators

  • mattcollins84