Description
A component of nestcloud. NestCloud is a nest framework micro-service solution.
This is a Nest module provide service registration and service discovery.
Installation
$ npm i --save nest-consul-service nest-consul consul
Quick Start
Import Module
;;;
If you use nest-boot module.
;;;;;
Nest-boot config file
web: serviceId: node1 serviceName: user-service port: 3001consul: host: localhost port: 8500 discovery_host: localhost health_check: timeout: 1s interval: 10s route: /health # when register / deregister the service to consul fail, it will retry five times. max_retry: 5 retry_interval: 5000
Usage
;;
API
class ConsulServiceModule
static register(options: RegisterOptions): DynamicModule
Import nest consul service module.
field | type | description |
---|---|---|
options.dependencies | string[] | if you are using nest-boot module, please set [NEST_BOOT] |
options.serviceId | string | the service id |
options.serviceName | string | the service name |
options.port | number | the service port |
options.consul.discovery_host | string | the discovery ip |
options.consul.health_check.timeout | number | the health check timeout, default 1s |
options.consul.health_check.interval | number | the health check interval,default 10s |
options.consul.health_check.deregistercriticalserviceafter | string | timeout after which to automatically deregister service if check remains in critical state |
options.consul.health_check.protocol | string | https or http, default is http. |
options.consul.health_check.route | string | the health check url, default is /health. |
options.consul.max_retry | number | the max retry count when register service fail |
options.consul.retry_interval | number | the retry interval when register service fail |
class ConsulService
getServices(serviceName: string, options?: object): Server[]
Get available services.
getAllServices()
Get all services
onServiceChange(service: string, callback: (servers: Server[]) => void): void
watch service change
onServiceListChange(callback: (newServices: string[]) => void): void
watch service list change
Stay in touch
- Author - Miaowing
License
Nest is MIT licensed.