# rabbitmq-lib

> RabbitMQ Abstraction Library

Latest version **2.4.0** (published 2026-10-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install rabbitmq-lib
pnpm add rabbitmq-lib
yarn add rabbitmq-lib
bun add rabbitmq-lib
```

## Health

**Score 60/100 (C)** — status: active.

Positive: no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 2.4.0 |
| Published | 2026-10-21 |
| First published | 2017-07-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 2 |
| Unpacked size | 49.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Luis Elizondo |
| Maintainers | luiselizondo |

## Links

- npm: https://www.npmjs.com/package/rabbitmq-lib
- Repository: https://github.com/luiselizondo/rabbitmq-lib
- Homepage: https://github.com/luiselizondo/rabbitmq-lib#readme
- Issues: https://github.com/luiselizondo/rabbitmq-lib/issues
- npm.io page: https://npm.io/package/rabbitmq-lib

## Dependencies (2)

- [uuid](https://npm.io/package/uuid.md) ^9.0.0
- [amqplib](https://npm.io/package/amqplib.md) ^0.10.3

## Recent versions

- 2.4.0 (latest) — 2026-10-21
- 2.3.2 — 2025-02-05
- 2.3.1 — 2025-02-05
- 2.2.2 — 2025-02-05
- 2.2.1 — 2025-01-27
- 2.2.0 — 2023-06-01
- 2.1.1 — 2021-05-14
- 2.1.0 — 2019-06-04
- 2.0.3 — 2019-03-09
- 2.0.2 — 2019-03-08
- 2.0.1 — 2019-03-06
- 2.0.0 — 2018-06-21
- 1.3.1 — 2018-06-10
- 1.3.0 — 2018-06-10
- 1.2.2 — 2017-10-31
- … 12 more at https://npm.io/package/rabbitmq-lib/versions

## README

# RabbitMQ Abstraction Library
RabbitMQ Lib abstract 3 common uses of RMQ in a very simple API you can use to send messages and consume them. 

Currently it supports Queues, Topics (publish/subscribe) and RPC.

This version also supports delayed message queues using the rabbitmq-delayed-message-exchange plugin.

On Version 2 we made a major rewrite of the module to better handle connections and channels and reuse them as much as possible.

I also split all the functionality in multiple classes you can use without having to load the whole library.

The library uses Node v8.x.x and it is not backwards compatible althought I tried to change as little as possible.

# Usage

Usage is better described on the tests folder. Take a look at each case but keep in mind that RabbitMQ will trigger an event using the instance passed in the constructor, you have to listen to events on that same instance.

Notes about RPC
When defining a listener, you always need to call next() as the second argument of the callback to be executed

# Manual acknowledgement

By default, `listen()` acknowledges a message as soon as it is delivered, so a handler cannot hold a message and tasks run concurrently as they arrive.

`listenManual(queueNames, handler, options)` consumes with manual acknowledgement instead: the `handler` is awaited and the message is acknowledged only after it resolves — the broker holds the next delivery until then, so one task is in flight at a time and a crashed container gets the task redelivered.

`options`:
- `prefetch` (default 1) and `globalPrefetch` (default true): how many unacknowledged messages this consumer may have. With `globalPrefetch: true` the limit is shared across all queues passed in the call.
- `onFailure`: `'ack'` (default) drops a message whose handler throws; `'requeue'` retries it once (via the redelivered flag) before dropping.
- `queueArguments`: extra arguments for `assertQueue` (e.g. `{ 'x-max-priority': 10 }`).

`send(queueName, message, delay, sendOptions)` also accepts `sendOptions.priority` (requires the queue to be declared with `x-max-priority`). Usage examples are in `tests/tests/queues.js` under `Queue listenManual`.

Notes about upgrading:

1. The library is much simpler and modular
2. Use Node v8 or greater
3. All librarys use listen() and send()

---
_Source: https://npm.io/package/rabbitmq-lib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
