1.0.0 • Published 8 years ago
mqemitter-child-process v1.0.0
mqemitter-child-process
Share the same mqemitter between a hierarchy of child processes
Install
npm install mqemitter-child-process --save
Example
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)
}
}
API
- mqemitterChildProcess.start()
- mqemitterChildProcess.stop()
- mqemitterChildProcess.unref()
- mqemitterChildProcess.child()
mqemitterChildProcess.start()
Starts the master mqemitter for this process.
mqemitterChildProcess.stop()
Stops the master mqemitter for this process.
mqemitterChildProcess.unref()
Calls unref()
on the main server
mqemitterChildProcess.chil()
Creates a MQEmitter child that connects to the master.
License
MIT
1.0.0
8 years ago