npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

busterbunny

v0.8.1

Published

Opinionated EventBus Library for amqplib

Downloads

8

Readme

busterbunny.js

Opinionated EventBus Library for amqplib

npm Coverage Status Build Status

Installation

npm install busterbunny

Dev Setup

npm install -g mocha
npm install -g istanbul
npm install coveralls
npm install mockery

Unit Testing

Testing can be run using the following command

npm run test

Code Coverage

Code Coverage provided by Instanbul with hooks for coveralls. To see coverage report run

npm run cover

Usage

var BusterBunny = require('busterbunny');

//example config
var config = {
    amqp: {
        cluster: {
            host: 'host.host.it',
            port: 5672,
            vhost: '/',
            login: 'someguy',
            password: '2insecure',
            heartbeat: 10
        },
        queues: [
            {
                name: 'i.read.from.this1'
            },
            {
                name: 'i.read.from.this2'
            }
        ],
        exchange: 'i.write.2.this1'
    },
    statsInterval: 10
};

//init buster bunny
var busterBunny = new BusterBunny(config.amqp);

//define an onAfterRaised callback
function onAfterRaised(err) {
    //handle the error if it exists, or continue
}

//raise event against bus
//this will be done when connection and channel is available

//raise events without AMQP options (see amqplib for available options)
busterBunny.raiseEvents('id.1001', { data: { x: 9001 } }, onAfterRaised);

//raise events, providing AMQP options 
busterBunny.raiseEvents('id.1002', { data: { x: 9002 } }, {amqp: 'options here'}, onAfterRaised);

//NOTE: calls to raiseEvents are required to provide a callback as the last parameter

//subscribe to events from bus
//this will be done when connection and channel is available
busterBunny.subscribe(function(event, message) {
    console.log("I found a " + event.type + " event!");

    doAnAsyncOperationWithTheEvent(event, function(error, someData) {
        if(error) {
            if(exception === 'we can recover from this error, eventually') {
                //requeue the message like this
                message.reject(true);

            } else {
                //or reject and remove it from the bus
                message.reject();
            }
        } else {
            message.acknowledge();
        }

    });
});

Events

Buster Bunny is an event emitter so it allows you to hook into the object to do things such as logging.
Buster Bunny provides events as a frozen object within buster bunny.

For example if you wanted to log warnings coming out of busterbunny

//This assumes you have required everything and have a logger
var busterBunny = new BusterBunny(config);

busterBunny.on(busterBunny.EVENTS.WARNING_RAISED, function(msg) {
    logger.warn(msg);
});

The current list of events (the property names) are ...

  1. WARNING_RAISED when a warning (like when a threshold is reached) has been reached
    • Parameters: warningMessage
  2. STATS when config.statsInterval is provided, busterbunny statistics are emitted at the specified interval of seconds
    • Parameters: stats
  3. READY when buster bunny has successfully established or re-established a connection and channels are available
    • No Parameters
  4. CONNECTING when buster bunny is establishing connections
    • Parameters: connection
  5. RECONNECTING after a connection has been lost but before it has been reconnected
    • No Parameters
  6. CONNECTED after a connection has been established
    • No Parameters
  7. DISCONNECTING when buster bunny is disconnecting its connection
    • No Parameters
  8. DISCONNECTED after a disconnection has been completed and stats have been flushed
    • No Parameters
  9. AMQP_ERROR when the amqplib throws an error
    • Parameters: error
  10. PUBLISH_CHANNEL_ESTABLISHED when buster bunny is ready to publish events to an exchange
    • No Parameters
  11. PUBLISH_REQUESTED when an event has been raised with buster bunny
    • No Parameters
  12. EVENT_RECEIVED when buster bunny has received an event from amqp
    • Parameters: event, message
  13. EVENT_ACKED when buster bunny has been asked to acknowledge an event
    • Parameters: event, message, timeAcked
  14. EVENT_NACKED when buster bunny has been asked to reject or requeue an event
    • Parameters: event, message, requeued, timeNacked

Some Opinions To Be Aware Of

  • The library tries to ALWAYS be connected to amqp over one connection with 1 channel for publishing and 1 for consuming.
  • The library also WARNS BUT DOENS'T REJECT when thresholds are hit allowing applications to handle the warning gracefully.
  • The library doesn't enforce the format of event messages.
  • The library does want all events to at least have an identifier and data.
  • The library requires specification of a callback for both subscribe and raiseEvents