concern-pool
v1.3.0
Published
a framework to facilitate inter-process communication between children processes using concerns.
Downloads
1
Readme
Concern Pool
a framework to facilitate inter-process communication between children processes using concerns.
Supported Features
- Messaging Strategy
| Messaging Strategy | Child to Master | Master to Child | Child to Child | |-------------------------|-----------------|-------------------|-------------------| | Pool Request/Response | N/A | YES (round-robin) | YES (round-robin) | | Single Request/Response | YES | YES | NO | | Publish To All | N/A | YES | YES | | Publish To One | YES | YES (round-robin) | NO |
- 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);