0.1.5 • Published 5 years ago
@uplatform/service-discovery v0.1.5
uPlatform - Service Discovery Component
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