amqplib
AMQP 0-9-1 client for Node.js to publish and consume messages with RabbitMQ queues and exchanges.
Official Documentation ↗v2.2.1. Check the official docs for the latest API surface.Installation
npm install amqplibpnpm add amqplibyarn add amqplibMethods
No methods match this filter.
Overview
amqplib speaks AMQP 0-9-1 to RabbitMQ, letting Node applications publish and consume messages through exchanges, queues and routing keys. It supports acknowledgements, confirms and dead-lettering.
Core Methods
Connect, then create a channel for most operations. assertQueue and assertExchange declare topology, sendToQueue or publish produce messages, and consume streams deliveries that you ack or nack.
Usage Notes
Declare durable topology, enable publisher confirms for reliability, and acknowledge only after processing succeeds. Route poison messages to a dead-letter queue instead of requeuing forever.
Common Pitfalls
Forgetting to ack leaves messages unacked and blocks the queue once the prefetch limit is reached. A channel-level error closes the whole channel, so recreate it. Auto-requeue on every failure can create an infinite redelivery loop.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/amqp-node/amqplib@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:48:08.078Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- If it throws, or returns something other than a finite, non-negative number, amqplib does not fall back to the built-in strategy. (https://cdn.jsdelivr.net/gh/amqp-node/amqplib@latest/README.md)
- Instead recovery gives up as if maxRetries had been exhausted: the initial connect rejects (or the callback receives the error), pending channel operations reject, and reconnect-failed is emitted with the error. (https://cdn.jsdelivr.net/gh/amqp-node/amqplib@latest/README.md)
- Error handling in event handlers If a user-supplied event handler throws a synchronous error, the throw will propagate into amqplib internals. (https://cdn.jsdelivr.net/gh/amqp-node/amqplib@latest/README.md)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/amqp-node/amqplib@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:48:08.078Z.
- Depending on where in the call stack it escapes, this can silently swallow the error, or close the channel or connection. (https://cdn.jsdelivr.net/gh/amqp-node/amqplib@latest/README.md)
FAQ
- What is the difference between ack and nack?
- ack tells the broker the message was handled and removes it. nack rejects it, optionally requeuing or routing it to a dead-letter exchange for later inspection.
- How do I make messages survive a restart?
- Use a durable queue, persistent messages and confirm channels. Without publisher confirms you cannot know the broker stored the message before the connection dropped.
- Why does a channel close with an error?
- A protocol error such as publishing to a missing exchange closes the channel. Recreate the channel, declare topology idempotently, and log the close reason to find the cause.
Report a problem with this API docOpens a pre-filled issue on GitHub.