Opinionated EventBus Library for amqplib
npm install busterbunny
npm install -g mocha
npm install -g istanbul
npm install coveralls
npm install mockery
Testing can be run using the following command
npm run test
Code Coverage provided by Instanbul with hooks for coveralls. To see coverage report run
npm run cover
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'
}
};
//init buster bunny
var busterBunny = new BusterBunny(config.amqp);
//raise event against bus
//this will be done when connection and channel is available
busterBunny.raiseEvents('kicked.bucket.1001', { data: { count : 9001 } });
//subscribe to events from bus
//this will be done when connection and channel is available
busterBunny.onNextEvent(function(event) {
console.log("I found a " + event.type + " event!");
});
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 ...
WARNING_RAISED
when a warning (like when a threshold is reached) has been reachedREADY
when buster bunny has successfully established or re-established a connection and channels are availableCONNECTING
when buster bunny is establishing connectionsRECONNECTING
after a connection has been lost but before it has been reconnectedCONNECTED
after a connection has been establishedAMQP_ERROR
when the amqplib throws an errorPUBLISH_CHANNEL_ESTABLISHED
when buster bunny is ready to publish events to an exchangePUBLISH_REQUESTED
when an event has been raised with buster bunnyEVENT_RECEIVED
when buster bunny has received an event from amqpEVENT_ACKED
when buster bunny has been asked to acknowledge an eventEVENT_NACKED
when buster bunny has been asked to reject or requeue an event
- 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.