citdev-service-discovery
v5.3.1
Published
Module to access other microservices hosted in a Citizen Developer installation
Downloads
60
Readme
Citizen Developer Service Discovery
The Citizen Developer Service Discovery package provides an easy way to find or call other Citizen Developer microservices running in the Citizen Developer cluster. The locate function takes a service to locate and a callback. The callback function will recieve an error or a service object with the address and port to connect to. The callService function takes a service name, a paramters object, and an optional timeout and returns a Promise for the service call.
Setup
To utilize the services returned by the locate function you will need install zeromq because all of the Citizen Developer microservices provide a zeromq endpoint.
Examples
var zmq = require('zeromq'),
ServiceDiscovery = require('citdev-service-discovery');
ServiceDiscovery.locate('expression_processor', function(err, service) {
if (err) {
//HANDLE SERVICE DISCOVERY ERROR
}
else {
// create a request to the end point
var requester = zmq.socket('req');
requester.connect('tcp://'+service.serviceAddress+':'+service.servicePort);
// handle replies from the responder
requester.on('message', function(result){
//HANDLE THE RESPONSE FROM THE SERVICE
requester.close();
});
requester.send(JSON.stringify({
'recordId': recordId,
'expression': expression
}));
}
});
var ServiceDiscovery = require('citdev-service-discovery');
ServiceDiscovery.callService('expression_processor', {
'recordId': recordId,
'expression': expression
}).then(function(expressionResult) {
console.log(expressionResult);
ServiceDiscovery.done();
});