node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »


build status # ZeroMQ Json RPC 2.0 Server ZeroMQ based JSON RPC 2.0 Server

Starting a service (Server)

Please refer to examples directory for more usage.

To define a service, just use any object with functions within it, an example would be

// Sample Service Object
var MyService = {
  getName: function() { return 'Hello, there'; },
  doubleIt: function(no) { return no*no; }

To start this as a service

var zmqrpc = require('zmqrpc').Server;
// first argument is zmqport
// second argument is debug
var service = new zmqrpc('tcp://', true);
// set the service object
// run the service;

The above service now has two methods, that can be called remotely

  • getName
  • doubleIt

Running a Client

Please refer to examples directory for more usage.

To define a client, its almost seamless like calling a local object with a callback function. For the above service, a client would be as

var zmqrpc = require('zmqrpc').Client;
// use the same port as given in server
var myobj = new zmqrpc('tcp://');
// call the method
// call back to have:
//   - first argument typically captures any errors
//   - second argument is the result from rpc service
myobj.getName(function(err, name) { 
  console.log('Got name:'+ name);