Pigato

PIGATO - an high-performance microservices framework based on ZeroMQ

View the Project on GitHub prdn/pigato

PIGATO

PIGATO

PIGATO - an high-performance Node.js microservices framework based on ZeroMQ

PIGATO aims to offer an high-performance, reliable, scalable and extensible service-oriented framework supporting multiple programming languages: Node.js/Io.js and Ruby.

Travis Build Status NPM version

Supported Programming Languages

Structure and Protocol

Actors

Benefits

Features

Examples

Start a Broker

node examples/broker

1) echo : simple echo request-reply

node examples/echo/worker
node examples/echo/client

2) stocks : get stocks data from yahoo

node examples/stocks/worker
node examples/stocks/client

More examples

PIGATO-EXAMPLES : a collection of multi-purpose useful examples.

Performance

PIGATO-PERF : a command-line tool to test PIGATO performances in different scenarios. i

API

Broker

PIGATO.Broker(addr, conf)

Simply starts up a broker.

var Broker = require('./../index').Broker;

var broker = new Broker("tcp://*:55555");
broker.start(function() {
  console.log("Broker started");
});

Events

Worker

PIGATO.Worker(addr, serviceName, conf)

Methods

on

Worker receives request events with 3 arguments:

reply writable stream exposes also following methods and attributes:

Example

var worker = new PIGATO.Worker('tcp://localhost:12345', 'my-service');
worker.start();

worker.on('request', function(data, reply, copts) {
  for (var i = 0; i < 1000; i++) {
    reply.write('PARTIAL DATA ' + i);
  }
  reply.end('FINAL DATA');
});

// or
worker.on('request', function(data, reply, copts) {
  fs.createReadStream(data).pipe(reply);
});

Worker may also specify whether the reply should be cached and the cache timeout in milliseconds

Example

worker.on('request', function(data, reply) {
  reply.opts.cache = 1000; // cache reply for 1 second
  reply.end('FINAL DATA');
});

Worker can change concurrency level updating its configuration. This information is carried with the heartbeat message.

Example

worker.conf.concurrency = 2;

Take note: due to the framing protocol of zmq only the data supplied to response.end(data) will be given to the client's final callback.

Events

Client

PIGATO.Client(addr, conf)

Methods

start

Start the Client

request

Send a Request

Example

var client = new PIGATO.Client('tcp://localhost:12345');
client.start()

client.request('my-service', { foo: 'bar' }, { timeout: 120000 })
.on('data', function(data) {
  console.log("DATA", data);    
})
.on('end', function() {
  console.log("END");     
});

// or
client.request('my-service', 'foo', { timeout: 120000 }).pipe(process.stdout);

Clients may also make request with partial and final callbacks instead of using streams.

Example

client.request('my-service', 'foo', function (err, data) {
  // frames sent prior to final frame
  console.log('PARTIAL', data);
}, function (err, data) {
  // this is the final frame sent
  console.log('FINAL', data);
}, { timeout: 30000 });

Events

Core Services

Core services are a set of Services that interact with a Broker via a dedicated PUB/SUB channel to extend its core functionalities.

Initialization

var broker = new PIGATO.Broker(bhost);
var csrv = new PIGATO.services.ExampleCoreService(bhost, {
  intch: broker.conf.intch // internal pub/sub channel                  
});
broker.start();
csrv.start();

Directory

PIGATO.services.Directory

Directory service ($dir) replies to Requests with the list of available Workers for a selected service.

Example

// Broadcast a message to all Workers that offer 'echo' Service
client.request(
  '$dir', 'echo', undefined, 
  function(err, workers) {
    workers.forEach(function(wid) {
      client.request('echo', 'foo', { workerId: wid });
    });
  }
);

Notes

Specification (good for RFC)

Protocol

Common

Client request

Worker reply

Changelog

CHANGELOG

Roadmap

Follow me

Contributors