Mongoose Pub/Sub
This node module implements pub/sub messaging using the "tailable cursor" feature of MongoDB capped collections.
Features
- Easily implement pub/sub without adding new infrastructure
- Sub-millisecond messaging
- Send javascript objects as messages
Installation
npm install mongoose-pubsub
Use
var MessageQueue = ;var messenger = ; //channel names are used as filtersvar channelName = 'news';messenger; //subscribemessenger; //unsubscribe // connect() begins "tailing" the collectionmessenger; // you can send without connect() first.messenger;
See the test directory for more information.
Note: The best way to use this in your application is to create a file like the following that exports a singleton. Then, when you require this in multiple files in your app, you always get the same instance.
// in lib/messenger.js ...var MessageQueue = ;moduleexports = retryInterval: 100; // in other files in your app ...var messenger = ;messenger
Tests
npm test
npm run lint
npm run coverage