Skip to content

qiwi/consul-service-discovery

Repository files navigation

Consul service discovery

CI npm (tag) Maintainability Test Coverage CodeStyle

Consul service discovery helper.

Install

  npm i @qiwi/consul-service-discovery
  yarn add @qiwi/consul-service-discovery

Usage

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 }

Configure

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
})

License

MIT