Socket
Book a DemoInstallSign in
Socket

mongoose-pubsub

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-pubsub

PubSub built on Mongoose

2.0.6
latest
Source
npmnpm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Mongoose Pub/Sub

NPM Package Build Status Coverage Status

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 = require('mongoose-pubsub');
var messenger = new MessageQueue();

//channel names are used as filters
var channelName = 'news';
messenger.subscribe(channelName, true); //subscribe
messenger.subscribe(channelName, false); //unsubscribe

// connect() begins "tailing" the collection
messenger.connect(function(){
  // emits events for each new message on the channel
  messenger.on(channelName, function(message){
    console.log(channelName, message);
  });
});

// you can send without connect() first.
messenger.send(channelName, {some: 'message'}, function(err){
  console.log('Sent message');
});

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 = require('mongoose-pubsub');
module.exports = new MessageQueue({retryInterval: 100});

// in other files in your app ...
var messenger = require('./lib/messenger');
messenger.on(...

Tests

npm test
npm run lint
npm run coverage

Keywords

mongoose

FAQs

Package last updated on 21 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.