consul
easy to use warper for consul to register to service discovery and get, merge and watch keys
Usage
import { Consul } from '@logzio-node-toolbox/consul';
const consul = new Consul({ port: 18500 });
methods
validateConnected - make use connected to consul service (will retry (connectMaxRetries) of times);
get(key) - will get a key from consul service
set(key, value) - will set value
keys(path) - list of keys in path
merge(key, values) - deepmerge values with key
watch(fn => ({key, onChange})) - will listen when key changed and invoke onChange
onChange will received the new ({key ,vale})
register({ meta, checks, address, hostname, serviceName, port, registerInterval }) - will register to service discovery and with given params will interval to make sure service is still registered
close() - deregister and close all watchers
multiConsul
extend consul to work on multiple keys and merged config
import { MultiConsul } from '@logzio-node-toolbox/consul';
const consul = new MultiConsul({ port: 18500, paths:['config1', 'config2', 'config3'] });
const values = await consul.getAll()
watchAll(({ key, value, changedValue }) => {
})