1.4.1 • Published 1 year ago

@magnet.me/consultant v1.4.1

Weekly downloads
176
License
Apache-2.0
Repository
github
Last release
1 year ago

Magnet.me Logo

Consultant

Fetches your service's configuration from Consul, and subscribes to any changes.

Install

npm install @magnet.me/consultant

What's Consultant?

Consultant is a Node library which allows your service to retrieve its configuration from Consul's Key/Value store as well as registering services. In addition to this, Consultant subscribes to any changes relevant to your service.

How to use Consultant?

Consultant consists of two separate functions, service and config which allow you to set up respectively the service registration and Key/Value configuration.

Both service and config require a single object parameter containing at least one service field, which acts as the service's identity. Using this identity the correct configuration can be fetched from Consul's Key/Value store. You must at the very least specify the service's name. You can also optionally specify the name of the data center where the service is running, the hostname of the machine the service is running on, and instance name to describe the role of this particular instance.

Alternatively you can also define this identity through environment variables:

Environment variableCorresponds toRequired
SERVICE_NAMEName of the serviceYes
SERVICE_DCName of the datacenter where the service is runningNo
SERVICE_HOSTThe name of the host where this service is running onNo
SERVICE_INSTANCEThe name of this particular instance of the serviceNo

Specifying an alternative Consul address

Consultant defaults Consul's REST API address to http://localhost:8500. If you wish to specify an alternative address to Consul's REST API, you can do so by setting the consulHost field.

Or alternatively you can also define the this through an environment variable:

Environment variableCorresponds to
CONSUL_HOSTAddress of Consul's REST API

Listening for config updates

config returns a promise which when resolved contains an object that allows consumers to register to updates in their configuration. This approach allows consumers to directly fetch the configuration, or subscribe to any changes made. For example:

import {config} from '@magnet.me/consultant';

const {register, getProperties} = await config({service:{name:'test-server'}});

console.log(getProperties());

register(properties => console.log(properties));
1.4.1

1 year ago

1.4.0

1 year ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

6 years ago

1.1.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago