Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

amqplib-auto-recovery

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amqplib-auto-recovery

Automatic connection recovery for amqplib

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
97
increased by19.75%
Maintainers
1
Weekly downloads
 
Created
Source

amqplib-auto-recovery

Automatic connection recovery for amqplib. Node.js 6+.

Installation

npm install amqplib-auto-recovery --save

Usage

Wrap amqp client with auto recovery decorator (like shown below). API stays absolutely the same as before *. The only difference is that amqp.connect(...)'s callback will be executed each time (re)connection is attempted (exponential backoff is turned on by default).

const amqp = require('amqplib/callback_api');
const withAutoRecovery = require('amqplib-auto-recovery');

withAutoRecovery(amqp, {
  // onError: (err) => { console.log(err.message) },
  // isErrorUnrecoverable: (err) => false
  // for more see src/amqplib-auto-recovery.js
}).connect("amqp://localhost", (err, con) => {
    if (err) {
      console.error(`Failed to connect (${err.message})`);
      return
    }
    console.info("Connection established");
    con.createChannel((err, ch) => {
      if (err) {
        console.error(`Failed to create a channel (${err.message})`);
        return
      }
      ch.prefetch(1, false);
      ch.assertQueue(consumer.queue, {durable: true});
      ch.consume(consumer.queue, (msg) => {
        // handle msg   
      });
    });
  });

* with exception to closed property (added to connection/channel), which might come in handy in situations like:

      // ...
      ch.consume(consumer.queue, (msg) => {
        // simulating a long-running task
        setTimeout(() => {
          if (ch.closed) {
            console.log("Channel had been closed before task was completed");
            return
          }
          ch.ack(msg); // throws IllegalOperationError if channel is closed
          // note that this is a standard amqplib behavior and not something
          // introduced by amqplib-auto-recovery
        }, 5000);
      });

License

MIT License

Keywords

FAQs

Package last updated on 18 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc