Share the same mqemitter between a hierarchy of child processes
ISC License
Share the same mqemitter between a hierarchy of child processes
npm install mqemitter-child-process --save
This example spins up 2 processes, and run the mqemitter in the master.
'use strict'
var childProcess = require('child_process')
var cp = require('./')
if (process.connected) {
client()
} else {
cp.start(function (err) {
if (err) { throw err }
for (var i = 0; i < 2; i++) {
childProcess.fork(__filename)
}
})
}
function client () {
var client = cp.child()
if (process.pid % 2 === 0) {
client.on('hello', function (msg, cb) {
console.log(msg)
cb()
})
} else {
setInterval(function () {
client.emit({ topic: 'hello', payload: 'world' })
}, 1000)
}
}
Starts the master mqemitter for this process.
Stops the master mqemitter for this process.
Calls unref()
on the main server
Creates a MQEmitter child that connects to the master.
MIT