amqplib

The promise- and callback-based AMQP 0-9-1 client for Node.js, built for connecting to and messaging over RabbitMQ.

Library
npm
v2.0.1
3,846stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
53/100Fair
Development Activity12
Maintenance20
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
71/100Good
Architecture80
Code Quality85
Innovation65
Learning Curve55

amqplib is a Node.js implementation of the AMQP 0-9-1 protocol used by RabbitMQ and other AMQP 0-9-1 brokers. It ships two API surfaces on top of one shared connection and channel core: a promise-based API (the default export) and a legacy callback API (amqplib/callback_api), so existing callback-style code and newer async/await code can coexist against the same library.

The library covers the full protocol: declaring and binding queues and exchanges, publishing and consuming messages, manual acknowledgment and rejection, consumer prefetch/QoS, and publisher confirms via a dedicated ConfirmChannel. Recent releases added an opt-in automatic-recovery mode with configurable backoff and a topology setup() hook, plus a handler-error event that catches synchronous throws inside user event listeners instead of letting them silently corrupt connection state.

What You Get

  • A promise-based default API (require('amqplib')) plus a callback-based API (require('amqplib/callback_api')) sharing one connection/channel core
  • Full queue/exchange management: assertQueue, assertExchange, bindQueue, bindExchange, and their check*/delete* counterparts
  • Publisher confirms via ConfirmChannel, with waitForConfirms() for batch confirmation
  • Consumer flow control through qos/prefetch, plus ack, nack, reject, and their *All variants
  • Opt-in automatic reconnect/recovery with configurable backoff, jitter, and a topology setup() hook
  • Hand-authored TypeScript type declarations (index.d.ts, callback_api.d.ts) for both API surfaces

Common Use Cases

  • Background job processing with queues and manual acknowledgment
  • Event-driven microservice communication via fanout/topic exchanges
  • Guaranteed message delivery with publisher confirms
  • Request/reply RPC over AMQP using direct reply-to
  • Long-running, self-healing consumers with automatic recovery

Under The Hood

Architecture The library is layered from the socket up: lib/connect.js parses the AMQP URL/options and opens a net/tls socket, lib/connection.js’s Connection class runs the opening handshake and frame accept loop against protocol definitions generated into lib/defs.js from the AMQP 0-9-1 spec (bin/amqp-rabbitmq-0.9.1.json), and lib/mux.js multiplexes per-channel write buffers onto the single socket. lib/channel.js provides the raw BaseChannel state machine (RPC dispatch, close handshake), while lib/channel_model.js layers the public Channel/ConfirmChannel/ChannelModel promise API on top, and lib/callback_model.js plus callback_api.js re-expose the same core as callbacks. This split means the two public entry points (channel_api.js and callback_api.js) are thin, divergent front ends over one shared protocol engine, so a change to the core affects both APIs identically.

Tech Stack Runtime dependencies are empty ("dependencies": {} in package.json) — the library relies solely on Node core modules (net, tls, node:stream Duplex/PassThrough, node:events) and targets Node >=18. Development tooling is Biome for linting and formatting, TypeScript purely for hand-maintained .d.ts declaration files (no compiled TS build step), lefthook for git hooks, and claire for property-based test generation. CI runs via GitHub Actions (test.yml, publish.yml), and the package is published as a dual-entry-point module via the exports map in package.json.

Code Quality Testing is extensive — over a dozen node:test-based suites totaling roughly 4,000 lines — and favors real socket-pair integration tests (test/lib/util.js sets up paired sockets and a fake AMQP server) over heavy mocking, exercising actual handshake and frame exchange behavior. Errors are modeled with a dedicated IllegalOperationError class and surfaced through both callback/promise rejection and error events; a newer handler-error event specifically catches synchronous throws from user-supplied listeners so they don’t silently corrupt channel or connection state. Biome linting is enforced in CI, and the closing-handshake state machine in connection.js is documented inline with an ASCII state diagram.

What Makes It Unique As the long-standing reference AMQP 0-9-1 client for Node.js, its differentiation is less about novel abstractions and more about protocol completeness and operational maturity: implementing the full method set (not just a common subset), maintaining a callback API alongside the promise API for backward compatibility, and recently adding an opt-in automatic-recovery mode with exponential backoff/jitter and a topology-redeclaration hook to address a long-standing pain point (silent disconnects) without changing behavior for callers who don’t opt in.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search