Pub/Sub for Node.js and MongoDB
vubsub is a Pub/Sub implementation for Node.js on top of MongoDB tailable cursors. vubsub was inspired by mubsub.
The main differences between vubsub and mubsub are:
- Active clients are tracked via a dedicated clients collection
- You can specify a namespace for each client (or group of clients): a namespace is a mapped to a collection (ns_namespace) where all the messages for that namespace are stored
- When connecting a client to a channel, you can specify the _id of the last received message and restart receiving message from that point.
vubsub uses Q, Kris Kowal's implementation of Promises.
How to Install
npm install vubsub
How to use
To create a new client, simply call the create function passing a db instance and, optionally, a metadata object. If the metadata contains the ns key, it'll be used as the namespace for the client (i.e. the client will be linked to a collection named ns_namespace). The metadata is stored, together with the client id in the clients collection (you can you this to keep track of your clients).
var vubsub =MongoClient = MongoClientMongoClient;
To create a channel and listen to events on the channel:
To send a message to a channel: