Consul service discovery helper.
npm i @qiwi/consul-service-discovery
yarn add @qiwi/consul-service-discovery
import ConsulServiceDiscovery from '@qiwi/consul-service-discovery'
const discovery = new ConsulServiceDiscovery({
host: '0.0.0.0', // local consul client host
port: 8000 // and port
})
const targetServiceName = 'example-api' // registered service
const serviceConnectionParams = await discovery.getConnectionParams(targetServiceName)
console.log(serviceConnectionParams) // { host: example-api-1234.qiwi.com, post: 8000 }
You may override some inner lib deps like logger (console by default) or Promise implementations:
ConsulServiceDiscovery.configure({
Promise, // Bluebird
logger, // log4js
Consul // consul client factory
})