amqplib
БесплатноБез исполняемых скриптовНе проверенamqplib is the Node.js client library for RabbitMQ and other AMQP 0-9-1 brokers. Use it to publish and consume messages from JavaScript or TypeScript: work…
Об этом скилле
amqplib
Overview
amqplib speaks AMQP 0-9-1 from Node.js. It is only the client: the broker, exchange types, policies, clustering and operations are covered by the rabbitmq skill. This skill is about the Node API and its pitfalls.
Version 2.x (2.2.0 in September 2026) keeps the 0.x/1.x API. What changed since the old tutorials:
- Types are bundled (since 1.2.0). Do not install
@types/amqplib; the DefinitelyTyped package stopped at 0.10.x. - Node.js 18 or newer (since 1.0.0), and 0.10.6 or later is required for RabbitMQ 4.1+ (frame size).
- Connection recovery is built in (since 1.1.0): pass
recoverytoconnectand the connection reconnects with backoff. heartbeat: 0now disables heartbeats (2.0.0). Before, it meant "use the server's value". Omit the option for the server default.- The promise API is the default import (
amqplib); the callback API lives inamqplib/callback_api.
Instructions
Install
npm install amqplib
docker run -d --name rabbit -p 127.0.0.1:5672:5672 -p 127.0.0.1:15672:15672 rabbitmq:4-management
Management UI: http://localhost:15672. Keep the broker URL in an environment variable such as RABBITMQ_URL (amqp://orders_app:<password>@localhost:5672/shop, TLS: amqps://). Do not use the default guest account outside the machine running the broker.
Connect once, open channels
A connection is one TCP socket; keep one per process. A channel is a lightweight session on it. Use one channel for publishing and a separate one for consuming, because a consumer that is blocked by prefetch should not stall publishes.
import amqp, { type ChannelModel, type ConsumeMessage } from "amqplib";
const connection = await amqp.connect(process.env.RABBITMQ_URL!);
connection.on("error", (err) => console.error("connection error", err.message));
connection.on("close", () => console.error("connection closed"));
A channel closes on any channel-level error (publishing to a missing exchange, acking twice, redeclaring a queue with different arguments). Attach channel.on("error", ...) and channel.on("close", ...) and open a new channel when it happens.
Declare topology with a dead-letter queue
const ch = await connection.createChannel();
await ch.assertExchange("orders.dlx", "fanout", { durable: true });
await ch.assertQueue("orders.failed", { durable: true });
await ch.bindQueue("orders.failed", "orders.dlx", "");
await ch.assertQueue("orders", {
durable: true,
arguments: { "x-dead-letter-exchange": "orders.dlx", "x-message-ttl": 86_400_000 },
});
assertQueue fails (and closes the channel) if the queue exists with different arguments. Change arguments by creating a new queue name or by using a RabbitMQ policy.
Publish with confirms
A plain channel's sendToQueue returns before the broker has the message. Use a confirm channel when losing a message matters:
const pub = await connection.createConfirmChannel();
async function publishOrder(order: { orderId: string; totalCents: number }) {
const ok = pub.sendToQueue("orders", Buffer.from(JSON.stringify(order)), {
persistent: true, // written to disk; the queue must be durable too
contentType: "application/json",
messageId: order.orderId,
});
if (!ok) await new Promise((resolve) => pub.once("drain", resolve)); // write buffer is full
await pub.waitForConfirms(); // rejects if the broker nacks any outstanding publish
}
publish(exchange, routingKey, content, options) is the exchange variant. A message published to an exchange with no matching queue is dropped silently unless you set mandatory: true and listen to the channel's return event.
Consume with manual acknowledgment
const sub = await connection.createChannel();
await sub.prefetch(10); // at most 10 unacknowledged messages per consumer
await sub.consume("orders", async (msg) => {
if (msg === null) return; // the broker cancelled the consumer (queue deleted, node down)
try {
await handleOrder(JSON.parse(msg.content.toString()));
sub.ack(msg);
} catch (err) {
// requeue once, then dead-letter; msg.fields.redelivered tells which attempt this is
sub.nack(msg, false, !msg.fields.redelivered);
}
});
Never pass noAck: true for work that must not be lost. Ack and nack each message exactly once, on the channel that delivered it. An unhandled exception inside the callback leaves the message unacknowledged until the channel closes.
Reconnect automatically
const conn = await amqp.connect(process.env.RABBITMQ_URL!, {
recovery: {
initialDelay: 200, // ms
maxDelay: 30_000,
maxRetries: Infinity,
initialMaxRetries: 5, // fail fast if the broker is down at startup
async setup(model: ChannelModel) { // runs after every (re)connect; the annotation is needed for TypeScript
const ch = awai
Установить amqplib в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл amqplib?
amqplib is the Node.js client library for RabbitMQ and other AMQP 0-9-1 brokers. Use it to publish and consume messages from JavaScript or TypeScript: work queues, topic exchanges, dead-letter queues, publisher confirms, manual acknowledgments, prefetch limits and automatic reconnection. Use when someone asks to "connect Node.js to RabbitMQ", "send messages to a queue from Node", "consume RabbitMQ messages in TypeScript", "retry failed jobs with a dead-letter queue" or "reconnect amqplib after the broker restarts". Covers amqplib 2.x.
Как установить скилл amqplib?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл amqplib запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic