Microfleet Consul Plugin
Adds consul support to microfleet. This can be used to perform
service discovery, leader election and other related tasks
Read more about Consul at https://www.consul.io
Install
yarn add @microfleet/plugin-consul
Configuration
To make use of the plugin adjust microfleet configuration in the following way:
exports.plugins = [
...,
'consul',
...
]
exports.consul = {
base: {
host?: string;
port?: string;
secure?: boolean;
ca?: string[];
defaults?: {
consistent?: boolean;
dc?: string;
stale?: boolean;
token?: string;
wait?: string;
wan?: boolean;
timeout?: number;
}
},
lock: {
key?: string;
session?: Object | string;
value?: string | Buffer;
lockwaittime?: string;
lockretrytime?: string;
}
}
Interface
Microfleet Consul Plugin extends service interface with the following methods:
service.consul: consul.Consul
Initialized instance. Look at the docs here - https://www.npmjs.com/package/consul#documentation
service.consulLeader: consul.Lock
Initialized leader election lock. Detailed docs here - https://www.npmjs.com/package/consul#lock
service.whenLeader(): Promise
Use this to wait until current instance becomes a leader.
const isLeader = await service.whenLeader()
if (isLeader === true) {
...
} else {
...
}