0.1.1 • Published 4 years ago

@hai.dinh/service-registry v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Service Registry

CI License: MIT

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-registry

API

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

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

Return (#service)

Interfaces

Service

PropertyDescription
idThis is id of service, which is handled as identification for register, get or unregister service.Type: string
nameThis is name of service, which should be readable.For e.g: "storage service".Type: string
categoryThe category of service. For e.g: "security", "logging", "storage".Type: string
endpointThe endpoint of service for other services can consume.For e.g: "http://storage-service:3000".Type: string
versionThe current version of service, which should be meet semver.For e.g: "1.0.0".Type: string

LICENSE

MIT