rabbit-pub-sub

A turn key npm for doing pub/sub using rabbitmq

npm install rabbit-pub-sub
25 downloads in the last week
49 downloads in the last month

rabbit-pub-sub Build Status

A turn key solution for doing pub/sub using rabbitmq.

What is this?

This project was written to try and minimise the friction in getting going with rabbitmq when using a publication/subscription model.

How do I install it?

npm install

You can install this plugin via the node package manager. The --save option will automnatically insert a package entry into you package.json.

npm install rabbit-pub-sub --save

What about the code?

A simple pub sub scenario below. Please make sure you dispose of your connections properly or else they will leak!!

var util = require("util");
var rabbit = require("rabbit-pub-sub");

var logger = {
    info: function(str) {
        console.log(str);
    }
};

var config = {
    server: "localhost",
    queue: "test-queue",
    exchange: "test-exchange"
};

var subscriber = new rabbit.MessageSubscriber(config, logger,
    function(message) {
        logger.info("Received message: " + util.inspect(message));
        //subscriber.end(); // Not doing this will leak connections!
    });

new rabbit.MessagePublisher(config, logger, function(publisher) {
    publisher.publish({
        name: "fir3pho3nixx",
        email: "fir3pho3nixx@gmail.com"
    });
    publisher.publish({ name: "any" });
    //publisher.end(); // Not doing this will leak connections!
});
npm loves you