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 🙏

© 2026 – Pkg Stats / Ryan Hefner

amqplib-recon

v1.2.5

Published

amqplib auto reconnection

Readme

amqplib-recon

npm i --save amqplib-recon

Simple usage example

var Amqp = require('amqplib-recon');
var amqp = new Amqp();

// Publisher
amqp.publish('queue', 'string');

// Consumer
amqp.consume('queue')
    .then(function(res){
        console.log(res.msg);
    });

Default config

var defaul_config = {
    url: 'amqp://guest:guest@localhost:5672',
    timeReconnect: 2000,
    channel: {
        mode: 'now', // is key modeHandlers
        timeCheckStatus: 1000,
        modeHandlers: {
            now: function(resolve, reject) {
                this.isConnected()
                    .then(resolve)
                    .catch(reject);
            },
            standby: function(resolve, reject) {
                (function check(delay) {
                    var next_delay = this.config.channel.timeCheckStatus;
                    var recheck = check.bind(this, next_delay);

                    this.isConnected()
                        .then(resolve)
                        .catch(setTimeout.bind(this, recheck, delay));
                }).call(this, 0);
            }
        }
    },
    queue: {
        durable: true
    },
    publish: {
        persistent: true
    },
    consume: {
        noAck: false,
        ackByHand: false
    }
};

#.channel( [options] )

Get the channel. Return Promise. By default options is taken from the defaul_config.channel and it has the same model

Examples:
var options = {
    mode: 'standby'
};

var data = {
    message: 'hello'
};

var onGetChannel = function(chn) {
    // chn is a amqplib channel object
    var queue = 'queue_name';
    chn.assertQueue(queue, {durable: true})
        .then(() => {
            var formatted_data = Buffer.from( JSON.stringify(data) );
            chn.sendToQueue(queue, formatted_data, {persistent: true});
        });
};

// "standby" mode
amqp.channel(options)
    .then(onGetChannel);

// "now" mode (by default)
amqp.channel()
    .then(onGetChannel)
    .catch(function() {
        // if the channel is not available do another
    });

#.publish( queue, content, [options] )

Return Promise. By default options is taken from the defaul_config.publish and it has the same model

Examples:
var data = {
    message: 'hello'
};

amqp.publish('queue', JSON.stringify(data))
    .then(function(){
        // success function
    })
    .catch(function(err){
        // fail function
    });

#.consume( queue, [options] )

Return Promise. By default options is taken from the defaul_config.consume and it has the same model

Examples:
var options = {
    ackByHand: true
};

amqp.consume('consumer', options)
    .then(function(res){
        var ack = res.ack;
        console.log(res.msg);

        if(ack){
            ack();
        }
    })