amqplib vs amqp-connection-manager vs @golevelup/nestjs-rabbitmq vs rascal
RabbitMQ Client Libraries Comparison
1 Year
amqplibamqp-connection-manager@golevelup/nestjs-rabbitmqrascal
What's RabbitMQ Client Libraries?

These libraries facilitate communication with RabbitMQ, a popular message broker, allowing developers to implement messaging patterns in their applications. They provide various features such as connection management, message publishing, and consumption, catering to different use cases and frameworks in Node.js applications.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
amqplib1,738,7093,768453 kB152 months agoMIT
amqp-connection-manager486,049544145 kB522 years agoMIT
@golevelup/nestjs-rabbitmq111,1822,540123 kB18a month agoMIT
rascal22,403468260 kB17 months agoMIT
Feature Comparison: amqplib vs amqp-connection-manager vs @golevelup/nestjs-rabbitmq vs rascal

Integration with Frameworks

  • amqplib:

    amqplib is a standalone library that can be used in any Node.js environment. It does not provide any framework-specific features but allows developers to build their own abstractions on top of its low-level API, giving maximum flexibility.

  • amqp-connection-manager:

    While not tied to any specific framework, this package can be integrated into any Node.js application. It provides a straightforward API for managing connections and channels, making it flexible for various architectures, including Express and Koa.

  • @golevelup/nestjs-rabbitmq:

    This package is designed specifically for NestJS, providing decorators and modules that integrate seamlessly with the framework's dependency injection and lifecycle management. It allows developers to easily create message producers and consumers within NestJS services and controllers.

  • rascal:

    Rascal can be used with any Node.js application and provides a higher-level API that abstracts away the complexities of RabbitMQ. It is particularly useful in applications that require a more structured approach to messaging.

Connection Management

  • amqplib:

    amqplib requires manual connection management, meaning developers must handle reconnections and channel management themselves. This offers flexibility but increases the complexity of the implementation.

  • amqp-connection-manager:

    This package excels in connection management, automatically handling reconnections and ensuring that channels are correctly managed. It provides options for configuring connection retries and backoff strategies, making it robust for production environments.

  • @golevelup/nestjs-rabbitmq:

    This library handles connection management internally, leveraging NestJS's lifecycle hooks to ensure connections are established and closed appropriately, reducing the risk of resource leaks.

  • rascal:

    Rascal simplifies connection management by providing built-in support for connection retries and error handling. It abstracts away much of the boilerplate code required for managing connections and channels.

Error Handling

  • amqplib:

    amqplib requires developers to implement their own error handling for message consumption and publishing. This allows for fine-tuned control but requires more effort to ensure robustness.

  • amqp-connection-manager:

    Error handling is primarily focused on connection issues. The library provides events for connection errors, allowing developers to implement custom logic for handling reconnections and failures.

  • @golevelup/nestjs-rabbitmq:

    This package integrates with NestJS's exception handling system, allowing developers to manage errors in a consistent manner across their application. It provides hooks for handling message processing errors gracefully.

  • rascal:

    Rascal provides built-in error handling features, including automatic retries and dead-letter queue support. It simplifies the process of managing errors in message processing, making it easier to build resilient applications.

Learning Curve

  • amqplib:

    amqplib has a steeper learning curve due to its low-level API and the need for developers to manage connections and channels manually. It requires a good understanding of RabbitMQ concepts to use effectively.

  • amqp-connection-manager:

    The learning curve is moderate, as developers need to understand connection management concepts but can quickly grasp the API due to its simplicity and clarity.

  • @golevelup/nestjs-rabbitmq:

    This package is relatively easy to learn for developers familiar with NestJS, as it follows the framework's conventions and patterns. The integration is straightforward, allowing for quick adoption.

  • rascal:

    Rascal is designed to be user-friendly, with a higher-level API that abstracts many complexities. This makes it easier for developers to get started with RabbitMQ messaging patterns without deep RabbitMQ knowledge.

Extensibility

  • amqplib:

    amqplib is highly extensible, allowing developers to build custom abstractions and utilities on top of its low-level API, making it suitable for advanced use cases.

  • amqp-connection-manager:

    While primarily focused on connection management, it can be extended by combining it with other libraries or custom logic to fit specific application needs.

  • @golevelup/nestjs-rabbitmq:

    This package is extensible within the NestJS ecosystem, allowing developers to create custom decorators and modules that integrate with RabbitMQ messaging seamlessly.

  • rascal:

    Rascal provides a flexible configuration system that allows for customization of messaging patterns and behaviors, making it extensible for various application requirements.

How to Choose: amqplib vs amqp-connection-manager vs @golevelup/nestjs-rabbitmq vs rascal
  • amqplib:

    Opt for amqplib if you need a low-level, flexible library for RabbitMQ. It offers a comprehensive API to interact with RabbitMQ directly, making it ideal for developers who want fine-grained control over messaging without additional abstractions.

  • amqp-connection-manager:

    Select this package for robust connection management with RabbitMQ. It handles automatic reconnections and provides a simple API for managing connections and channels, making it suitable for applications that require high availability and reliability.

  • @golevelup/nestjs-rabbitmq:

    Choose this package if you are using NestJS and want a seamless integration with RabbitMQ. It provides decorators and modules that align with NestJS's architecture, making it easier to implement message-driven microservices.

  • rascal:

    Use rascal if you prefer a higher-level abstraction with built-in support for common messaging patterns. It simplifies the setup of exchanges, queues, and bindings, and provides features like automatic retries and error handling, making it suitable for complex messaging scenarios.

README for amqplib

AMQP 0-9-1 library and client for Node.JS

NPM version NPM downloads Node.js CI amqplib

A library for making AMQP 0-9-1 clients for Node.JS, and an AMQP 0-9-1 client for Node.JS v10+. This library does not implement AMQP1.0 or AMQP0-10.

npm install amqplib

❤️ Help Support Jack

One of my close friends, Jack, was recently diagnosed with terminal brain cancer (grade 4 astrocytoma). He’s a young father facing an unimaginably tough road with remarkable courage. Thanks to chemotherapy, radiotherapy, and your support, two of his tumours have stopped showing activity. Donations help Jack continue accessing promising complementary therapies, attend hospital appointments, and spend meaningful time with his children.

If you’ve benefited from amqplib, please consider supporting Jack’s journey through his J Crushing Cancer gofundme page. Thank you - @cressie176

RabbitMQ Compatibility

Only 0.10.7 and later versions of this library are compatible with RabbitMQ 4.1.0 (and later releases).

Links

Project status

  • Expected to work
  • Complete high-level and low-level APIs (i.e., all bits of the protocol)
  • Stable APIs
  • A fair few tests
  • Measured test coverage
  • Ports of the RabbitMQ tutorials as examples
  • Used in production

Still working on:

  • Getting to 100% (or very close to 100%) test coverage

Callback API example

const amqplib = require('amqplib/callback_api');
const queue = 'tasks';

amqplib.connect('amqp://localhost', (err, conn) => {
  if (err) throw err;

  // Listener
  conn.createChannel((err, ch2) => {
    if (err) throw err;

    ch2.assertQueue(queue);

    ch2.consume(queue, (msg) => {
      if (msg !== null) {
        console.log(msg.content.toString());
        ch2.ack(msg);
      } else {
        console.log('Consumer cancelled by server');
      }
    });
  });

  // Sender
  conn.createChannel((err, ch1) => {
    if (err) throw err;

    ch1.assertQueue(queue);

    setInterval(() => {
      ch1.sendToQueue(queue, Buffer.from('something to do'));
    }, 1000);
  });
});

Promise/Async API example

const amqplib = require('amqplib');

(async () => {
  const queue = 'tasks';
  const conn = await amqplib.connect('amqp://localhost');

  const ch1 = await conn.createChannel();
  await ch1.assertQueue(queue);

  // Listener
  ch1.consume(queue, (msg) => {
    if (msg !== null) {
      console.log('Received:', msg.content.toString());
      ch1.ack(msg);
    } else {
      console.log('Consumer cancelled by server');
    }
  });

  // Sender
  const ch2 = await conn.createChannel();

  setInterval(() => {
    ch2.sendToQueue(queue, Buffer.from('something to do'));
  }, 1000);
})();

Running tests

npm test

To run the tests RabbitMQ is required. Either install it with your package manager, or use docker to run a RabbitMQ instance.

docker run -d --name amqp.test -p 5672:5672 rabbitmq

If prefer not to run RabbitMQ locally it is also possible to use a instance of RabbitMQ hosted elsewhere. Use the URL environment variable to configure a different amqp host to connect to. You may also need to do this if docker is not on localhost; e.g., if it's running in docker-machine.

One public host is dev.rabbitmq.com:

URL=amqp://dev.rabbitmq.com npm test

NB You may experience test failures due to timeouts if using the dev.rabbitmq.com instance.

You can run it under different versions of Node.JS using nave:

nave use 10 npm test

or run the tests on all supported versions of Node.JS in one go:

make test-all-nodejs

(which also needs nave installed, of course).

Lastly, setting the environment variable LOG_ERRORS will cause the tests to output error messages encountered, to the console; this is really only useful for checking the kind and formatting of the errors.

LOG_ERRORS=true npm test

Test coverage

make coverage
open file://`pwd`/coverage/lcov-report/index.html