Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@hai.dinh/service-registry

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hai.dinh/service-registry

client-side service discovery for microservice

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

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

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

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

Keywords

service-registry

FAQs

Package last updated on 26 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts