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

amqp-hutch

v1.0.20

Published

amqplib wrapper

Downloads

16

Readme

AMQP:Hutch

amqplib wrapper for easy setup and initialization.

Setup

Configuration and Events for AMQP Hutch.

var AMQPHutch = require('amqp-hutch');

var hutch = new AMQPHutch();

hutch.initialise({
  connectionString: 'amqps://user:password@host:port/uri?heartbeat=3',
  retryWait:        1000
});

hutch.on('ready', function() {
  console.log('Established RabbitMQ connection');
});

hutch.on('close', function(err) {
  console.log(err.message + 'RabbitMQ closing connection');
});

hutch.on('error', function(err) {
  console.log(err.message + 'RabbitMQ connection error');
});

module.exports = hutch;

Publish

var message = {"Message": "Hello"};

var options = {
  exchange: {
    durable: true,
    confirm: true,
    autoDelete: false,
    type: 'topic',
    name: 'example.exchange'
  },
  publish: {
    persistent: true,
    contentType: 'application/json',
    expiration: 86400000,
    timestamp: Math.floor(Date.now() / 1000)
  }
};

hutch.publish(options, message, function(err, res) {
  console.log(res);
});

Publish to Exchange

var message = {"Message": "Hello"};

var publishOptions = {
  exchange: {
    durable: true,
    confirm: true,
    autoDelete: false
  },
  publish: {
    persistent: true,
    contentType: 'application/json',
    expiration: 86400000,
    timestamp: Math.floor(Date.now() / 1000)
  }
};

hutch.publishToExchange('exchange.name', 'topic', publishOptions, message, function(err, res) {
  console.log(res);
});

Consume

Consume creates a queue bound to a new channel.


  var options = {
    exchange: {
      name: 'exchange.name',
      type: 'topic'
    },
    queue: {
      name: 'queue.name',
      prefetch: 1,
      durable:  true
    },
    routingKey: '#'
  };

  var consumer = function(message, done, fail) {
    some.service(message, function(err, res) {
      if(err) return fail();    
      done();
    });
  };

  hutch.consume(options, consumer, function(err) {
    console.log("Successfully setup consumer for queue: [" + options.queue + "]");
  });

Exclusive

Adding the Exclusive flag to the options will manage an exclusive consumer, the conusmer will retry until closed.


  var options = {
    exchange: {
      name: 'exchange.name',
      type: 'topic'
    },
    queue: {
      name: 'queue.name',
      prefetch: 1,
      durable:  true
    },
    exclusive: true
  };

SkipNext

Adding the skipNext flag to the options will skip the next message in the queue before initialising, this can be useful for unblocking failed messages.


  var options = {
    exchange: {
      name: 'exchange.name',
      type: 'topic'
    },
    queue: {
      name: 'queue.name',
      prefetch: 1,
      durable:  true
    },
    skipNext: true
  };

Destroy

Destroy will unbind/purge the queue from the given exchange.

  var queue    = "queue.name";
  var exchange = "exchange.name";

  hutch.destroy(queue, exchange, function(err) {
    console.log("Successfully unbound queue: [" + queue + "]");
  });

Monitoring

amqp-hutch offers two properties which may come in helpful for monitoring.

status

The status property can contain two values CONNECTED or DISCONNECTED.

configuration

The configuration object contains the original configuration passed to amqp-hutch.

  if (hutch.isConnected()){
    console.log(hutch.configuration.connectionString)
  }

Error Handing

Errors triggered from the underlinging service calls with RabbitMQ can be caught by listening for events.

hutch.on('error', function(err) {
  console.log(err);
});

If the service is invoked prior to a connection been established the service will return a 'AMQPConnectionError'