@uplatform/service-discovery

0.1.5 • Public • Published

uPlatform - Service Discovery Component

npm version license

How to use

Install the module:

npm install --save @uplatform/service-discovery

Configure the Service Discovery:

const { ServiceDiscovery } = require('@uplatform/service-discovery');
const discovery = new ServiceDiscovery({ name: 'my-app-1' });

Start Redis:

docker run --rm -it -p 127.0.0.1:6379:6379/tcp redis

Start the application:

export REDIS_URL=redis://my-redis-url:6379
node app.js

Note: By default is uses a Redis server as a backend and gets an URL from REDIS_URL.

Snippets

Publishing a new service instance

const instance = await discovery.publish({
    name: 'app-1',
    type: 'http',
    metadata: {
        api: '1.12',
    },
    location: {
        host: '10.0.0.12',
        port: 16784,
        path: '/api/v1',
    },
});

Unpublishing an existing service instance

await discovery.unpublish(instance);

Looking up a service by name

const serviceRef = await discovery.lookup({
    name: 'app-1',
});

Looking up a service by type

const serviceRef = await discovery.lookup({
    name: 'app-1',
    type: 'http',
});

Looking up a service by metadata

const serviceRef = await discovery.lookup({
    name: 'app-1',
    type: 'http',
    api: '1.12',
});

TODO

  • Implement ServiceRef.asPgClient()
  • Implement ServiceRef.asRedisClient()
  • Implement ServiceRef.asMongoClient()
  • Implement live update of instance list.

Authors

  • Karabutin Alex

Package Sidebar

Install

npm i @uplatform/service-discovery

Weekly Downloads

0

Version

0.1.5

License

MIT

Unpacked Size

17.4 kB

Total Files

10

Last publish

Collaborators

  • karabutin-alex