/mongodb-pubsub

MongoDB backed pub/sub

Primary LanguageJavaScriptMIT LicenseMIT

mongodb-pubsub

Build Status

Turns MongoDB into a pub/sub message broker.

Based on this enligtening blog post.

Install

npm install mongodb-pubsub

Example

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
  })
});

API Documentation

Source code documentation can be generated by running npm install && npm run-script doc. Generated documentation will be in the ./doc directory.

Testing

npm install && npm test

License

Copyright 2014 Clay Walker
MIT License