1.3.0 • Published 6 months ago

concern-pool v1.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

Concern Pool

a framework to facilitate inter-process communication between children processes using concerns.

Supported Features

  1. Messaging Strategy
Messaging StrategyChild to MasterMaster to ChildChild to Child
Pool Request/ResponseN/AYES (round-robin)YES (round-robin)
Single Request/ResponseYESYESNO
Publish To AllN/AYESYES
Publish To OneYESYES (round-robin)NO
  1. Automatic child-process respawn.

Example

Master Process ...

const master = new MasterProcess();
const helloWorkers = master.addWorkers('Hello#', 3, 'path/to/hello-module.js');
const helloConcern = this.master.register('hello-pool', helloWorkers);

const httpWorkers = master.addWorkers('Http#', 2, 'path/to/http-module.js');
const httpConcern = this.master.register('http-pool', httpWorkers);

// Master to child pool request/response
helloConcern.request('hello', 3000)
  .then(result =>{
    console.log('result on master: ', result); // prints 'hi'
  })
  .catch(err=>{
    console.error(err);
  });

Child Process (hello-module)...

const master = new MasterProcess();
process.on('message', (msg)=>{
  if (msg.d === 'hello' && msg.r){
    process.send!({r: msg.r, d: 'hi'});
  }
})

Child Process (http-module)...

const master = new MasterProcess();
const http = require('http');

http.createServer((req, res) => {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  // child-to-child pool request/response.
  master.request('hello', 'hello-pool') // request data, concern-pool
    .then(result =>{
      res.end(result); // prints 'hi' as an http response.
    })
    .catch(err=>{
      res.end(err);
    });
}).listen(8080);