citdev-service-discovery

5.3.1 • Public • Published

Citizen Developer Service Discovery

npm version

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

Readme

Keywords

none

Package Sidebar

Install

npm i citdev-service-discovery

Weekly Downloads

1

Version

5.3.1

License

ISC

Unpacked Size

29.2 kB

Total Files

4

Last publish

Collaborators

  • bbransteitter