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

@klicksite/roger-rabbit

v5.3.6

Published

amqplib wrapper

Downloads

5

Readme

Roger Rabbit

Travis Codecov npm npm

Roger Rabbit is a module that makes the process of consuming and publishing messages in message brokers easier. It is a wrapper for amqplib.

Install

npm install @klicksite/roger-rabbit --save

Documentation

Broker

Broker expect to receives a rabbitMQ connection string and broker options. Example:

// broker.js
const Broker = require('roger-rabbit');

const broker = new Broker('amqp://guest:guest@localhost:5672');

module.exports = broker;

broker.init

Use broker.init to initialize broker, creating connections and channels based on broker options. Example:

// main.js
const broker = require('./broker');

(async() => {
  await broker.init();
})();

broker.assertExchanges

Use broker.assertExchanges to create or check exchanges. It expects to receive an array of exchanges (exchange options). Example:

const broker = require('./broker');

const exchanges = [
  { name: 'user_events', type: 'direct' },
  { name: 'repo_events', type: 'topic', options: { durable: true } },
  { name: 'commit_events', type: 'fanout' },
];

(async() => {
  await broker.assertExchanges(exchanges);
})();

broker.consume

broker.consume expects to receive an object with queue and array of bindings and callback. Example:

const broker = require('./broker');

const queue = {
  name: 'queue.name',
  options: {
    durable: true,
  },
};

const bindings = [
  { exchange: 'user_events', routingKey: 'user_events.routingKey' },
  { exchange: 'repo_events', routingKey: 'repo_events.routingKey' },
];

(async() => {
  await broker.consume({ queue, bindings }, (message, /* fields */) => {
    // do something
    // throw an error to reject message
  });
})();

broker.publish

broker.publish expects to receive exchange, routing key, message and publish options. Example:

const options = { persistent: true };

broker.publish({
    exchange: 'user_events',
    routingKey: 'user_events.routingKey',
    message: { message: 'message' },
    options,
  })

broker.channels

Use broker.channels to get channels. Examples:

const broker = require('./broker');
let context;
let channel;

//consumer
context = 'consumer';
channel = broker.channels[context].default;

//publisher
context = 'publisher';
channel = broker.channels[context].default; // or broker.channels[context].confirmation;

Broker options

| Option | Description | Required | Default | | ------------------------|---------------------------------------------|-----------|---------| | channelMax | number max of channels (max 3) | no | 3 | | publisher | publisher object | no | _ | | publisher.default | create publish channel without confirmation | no | true | | publisher.confirmation | create publish channel with confirmation | no | false | | consumer | consumer object | no | _ | | consumer.default | create consume channel | no | true | | prefetch | channel prefetch count | no | 1 |

Exchange options

| Option | Description | Default | | --------|-----------------------------------------------------------------------------------------------------------------|-------------------------| | type | direct, topic, fanout | empty string (deafault) | | name | exchange name | null | | options | options used in assertExchange | null |

Queue options

| Option | Description | Default | | --------|-----------------------------------------------------------------------------------------------------------|---------| | name | queue name | null | | options | options used in assertQueue | null |

Binding options

| Option | Description | Default | | -----------|------------------|---------| | exchange | exchange name | null | | routingKey | routing key name | null |