Inter-worker message-based communication in the node cluster. Based on this gist.
$ npm install --save hoot
var hoot = require('hoot');
// in cluster master when creating workers
worker = cluster.fork();
hoot.registerWorker(worker);
// in worker
hoot.send('rainbow', { colors: 7 });
hoot.on('rainbow', function(data) {
// all workers will see that
console.log('Rainbow has ', data.colors, ' colors');
});
Any worker can call send
to broadcast message
to all running workers.
data
can be passed along the message to the listener
Worker registers listener function for each message
separately.
listener
receives message data
as its argument.
Cluster master needs to call registerWorker
for all workers that participate in message exchange.
MIT © Damian Krzeminski