Class for persistent AMQP connections


2.0.33 years ago3 years agoMinified + gzip package size for @johnmmackey/amqp-persistent in KB



Wrapper for ampqlib providing persistent connection to the AMQP server.

Due to the use of ES6 features, this module requires Node.js V8 or above.


npm install @johnmmackey/amqp-persistent
const { amqpPersistentConnection } = require('@johnmmackey/amqp-persistent');

// Establish a connection to server
// Server URI is taken from AMQP_URI environment variable.
// If not set, defaults to 'amqp://localhost'

// Alternately, a server can be specified:

amqpPersistentConnection is an instance of EventEmitter. Events:

  • debug: informational
  • ready: when connection is ready
  • failed: if connection drops

Usage example:

    amqpPersistentConnection.on('debug', status => {
        console.log('AMPQ Connection debug:', status);

Core Methods

A connection has the following core methods:

  • addConfig(f), where f is a function returning a promise. Example:
    amqpPersistentConnection.addConfig(async ch => {
        await ch.assertExchange('sillyex', 'fanout');
        await ch.assertQueue('sillyq');
        await ch.bindQueue('sillyq', 'sillyex', '');
        ch.consume('sillyq', msg => {
        }, { noAck: true });
  • amqpPersistentConnection.ack(msg) - acknowledge a message (used in consumer functions)

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.