mqemitter-child-process

1.0.0 • Public • Published

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()

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

Package Sidebar

Install

npm i mqemitter-child-process

Weekly Downloads

3

Version

1.0.0

License

MIT

Last publish

Collaborators

  • matteo.collina