Turns MongoDB into a pub/sub message broker.
Based on this enligtening blog post.
npm install mongodb-pubsub
var PubSub = require('mongodb-pubsub')
, util = require('util');
// create a new instance
var ps = new PubSub();
// open the connection to the broker
ps.open(function (err) {
if (err !== null) throw err;
// you can use the local events or the callbacks
ps.on('subscribe', function () {
ps.publish('foo', 'bar', 'baz'); // takes multiple arguments
});
// subscribe to a channel
ps.subscribe('foo', function () {
console.log('got a foo!', util.inspect(arguments));
ps.close(); // tidy up
})
});
Source code documentation can be generated by running npm install && npm run-script doc
. Generated documentation will be in the ./doc
directory.
npm install && npm test
Copyright 2014 Clay Walker
MIT License