mongodb-pubsub

0.0.1 • Public • Published

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

Package Sidebar

Install

npm i mongodb-pubsub

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • clayzermk1