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

bunnymq

v2.5.0

Published

BunnyMq is a RabbitMq wrapper

Downloads

177

Readme

node-bunnymq

Circle CI npm npm Sonar Sonar Sonar Sonar Sonar Sonar

npm

Features

  • Subscriber (consumer)
  • Publisher (producer)
  • RPC (get answers from subscriber automatically)
  • Auto connect/reconnect/queue messages
  • Handle errors / requeing when message callback fails
  • Messages types caring using AMQP headers for content type (send as objects and receive as objects)

Installation

bunnymq requires nodejs 6 or harmony flags! because it uses es6 features outside strict mode.

npm install bunnymq

Basic usage

Publisher

Producer (publisher), can send messages to a named queue.

const bunnymq = require('bunnymq')({ host: 'amqp://localhost' });
bunnymq.publish('queue:name', 'Hello World!');

Subscriber

Consumer (subscriber), can handle messages from a named queue.

const bunnymq = require('bunnymq')({ host: 'amqp://localhost' });

bunnymq.subscribe('queue:name', function (msg) {
  //msg is the exact item sent by a producer as payload
  //if it is an object, it is already parsed as object
});

RPC Support

You can create RPC requests easily by adding the rpc: true option to the produce call:

bunnymq.subscribe('queue:name', function() {
  return 'hello world!'; //you can also return a promise if you want to do async stuff
});

bunnymq.publish('queue:name', { message: 'content' }, { rpc: true, timeout: 1000 })
.then(function(consumerResponse) {
  console.log(consumerResponse); // prints hello world!
});

The optional timeout option results in a rejection when no answer has been received after the given amount of milliseconds. When '0' is given, there will be no timeout for this call. This value will overwrite the default timeout set in the config in rpcTimeout.

Routing keys

You can send publish commands with routing keys (thanks to @nekrasoft)

bunnymq.publish('queue:name', { message: 'content' }, { routingKey: 'my-routing-key' });

Config

You can specify a config object, properties and default values are:

  const bunnymq = require('bunnymq')({
    host: 'amqp://localhost',
    //number of fetched messages at once on the channel
    prefetch: 5,
    //requeue put back message into the broker if consumer crashes/trigger exception
    requeue: true,
    //time between two reconnect (ms)
    timeout: 1000,
    //default timeout for RPC calls. If set to '0' there will be none.
    rpcTimeout: 1000,
    consumerSuffix: '',
    //generate a hostname so we can track this connection on the broker (rabbitmq management plugin)
    hostname: process.env.HOSTNAME || process.env.USER || uuid.v4(),
    //the transport to use to debug. if provided, bunnymq will show some logs
    transport: utils.emptyLogger
  });

You can override any or no of the property above.

Note: if you enable the debug mode using the AMQP_DEBUG=true env var, but you do not attach any transport logger, the module will fallback to console.

Env vars

Deprecated as of 2.1.0, don't use env vars to configure the module, see Config section.

Documentation & resources

To generate documentation, just run npm run docs, it will create a docs folder.

You can also find more about RabbitMq in the links below:

  • http://www.rabbitmq.com/getstarted.html
  • https://www.cloudamqp.com/blog/2015-05-18-part1-rabbitmq-for-beginners-what-is-rabbitmq.html
  • http://spring.io/blog/2010/06/14/understanding-amqp-the-protocol-used-by-rabbitmq/

Tests

Requirements:

  • docker
  • npm
  • make

Run make deps once and then make test to launch the test suite.

License

The MIT License MIT