0.1.1 • Published 6 years ago
@hai.dinh/service-registry v0.1.1
Service Registry
A client-side service discovery for microservice using etcd.
Installation
The easiest way to install service-registry is using NPM. If you have Node.js installed, it is most likely that you have NPM installed as well.
$ npm install @hai.dinh/service-registryAPI
register
register(opts: Service): Service
.register() create a new service in service catalog
import ServiceRegistryFactory from @hai.dinh/service-registry
const registry = ServiceRegistryFactory.create({
driver: 'etcd',
hosts: '127.0.0.1:2379',
env: 'dev'
})
const response = await registry.register({
id: 'storage-service',
name: 'storage service',
endpoint: 'http://storage-service:3001',
category: 'core',
version: '0.0.1'
})Parameter
- opts: Service
Return Service
unregister
unregister(id: string): boolean
.unregister() delete the specified service in service catalog
import ServiceRegistryFactory from @hai.dinh/service-registry
const registry = ServiceRegistryFactory.create({
driver: 'etcd',
hosts: '127.0.0.1:2379',
env: 'dev'
})
const isDeleted = await registry.unregister('storage-service');Parameter
- id: string
Return boolean
get()
get(id: string): Service
.get() to retrieve the specified service in service catalog
import ServiceRegistryFactory from @hai.dinh/service-registry
const registry = ServiceRegistryFactory.create({
driver: 'etcd',
hosts: '127.0.0.1:2379',
env: 'dev'
})
const storageService = await registry.get('storage-service')Parameter
- id: string
Return Service
list
list(): []Service
.list() to retrieve service catalog
import ServiceRegistryFactory from @hai.dinh/service-registry
const registry = ServiceRegistryFactory.create({
driver: 'etcd',
hosts: '127.0.0.1:2379',
env: 'dev'
})
const services = await registry.list()Interfaces
Service
| Property | Description |
|---|---|
| id | This is id of service, which is handled as identification for register, get or unregister service.Type: string |
| name | This is name of service, which should be readable.For e.g: "storage service".Type: string |
| category | The category of service. For e.g: "security", "logging", "storage".Type: string |
| endpoint | The endpoint of service for other services can consume.For e.g: "http://storage-service:3000".Type: string |
| version | The current version of service, which should be meet semver.For e.g: "1.0.0".Type: string |