amqplib
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "amqplib":https://skillpi.com/zh/skills/deepskill-fc40f8d44275e522172036d90aba07e1582fa448521c7ca6a638361b251743d0。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
你是 amqplib 专家。amqplib 是用于 RabbitMQ 和 AMQP 0-9-1 协议的 Node.js 客户端。帮助开发者实现可靠的消息队列模式,包括工作队列、发布/订阅(扇形交换)、主题路由、RPC 模式、死信队列与消息确认机制,构建通过 RabbitMQ 异步通信的解耦微服务。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 实测状态
- 未测试
文件浏览
Frontmatter
name: amqplib
description: >-
You are an expert in amqplib, the Node.js client for RabbitMQ and AMQP
0-9-1 protocol. You help developers implement reliable message queuing with
work queues, pub/sub fanout, topic routing, RPC patterns, dead letter
queues, and message acknowledgment — building decoupled microservices that
communicate asynchronously through RabbitMQ.
license: Apache-2.0
compatibility: ''
metadata:
author: terminal-skills
version: 1.0.0
category: Backend Development
tags:
- rabbitmq
- amqp
- messaging
- queue
- microservices
- asyncamqplib — RabbitMQ Client for Node.js
You are an expert in amqplib, the Node.js client for RabbitMQ and AMQP 0-9-1 protocol. You help developers implement reliable message queuing with work queues, pub/sub fanout, topic routing, RPC patterns, dead letter queues, and message acknowledgment — building decoupled microservices that communicate asynchronously through RabbitMQ.
Core Capabilities
Producer and Consumer
import amqp from "amqplib";
// Producer — send messages to queue
async function sendToQueue(queue: string, message: any) {
const connection = await amqp.connect(process.env.RABBITMQ_URL!);
const channel = await connection.createChannel();
await channel.assertQueue(queue, {
durable: true, // Survive broker restart
arguments: {
"x-dead-letter-exchange": "dlx", // Failed messages go to DLX
"x-message-ttl": 86400000, // 24h TTL
},
});
channel.sendToQueue(queue, Buffer.from(JSON.stringify(message)), {
persistent: true, // Survive broker restart
contentType: "application/json",
messageId: crypto.randomUUID(),
timestamp: Date.now(),
});
await channel.close();
await connection.close();
}
// Consumer — process messages reliably
async function startConsumer(queue: string, handler: (msg: any) => Promise<void>) {
const connection = await amqp.connect(process.env.RABBITMQ_URL!);
const channel = await connection.createChannel();
await channel.assertQueue(queue, { durable: true });
await channel.prefetch(10); // Process 10 at a time
channel.consume(queue, async (msg) => {
if (!msg) return;
try {
const data = JSON.parse(msg.content.toString());
await handler(data);
channel.ack(msg); // Success — remove from queue
} catch (error) {
console.error("Processing failed:", error);
channel.nack(msg, false, false); // Failed — send to DLX (no requeue)
}
});
}
// Usage
await sendToQueue("orders", { orderId: "ORD-123", total: 99.99 });
await startConsumer("orders", async (order) => {
await processOrder(order);
await sendEmail(order);
});
Pub/Sub with Exchanges
// Topic exchange — route messages by pattern
async function setupTopicExchange() {
const connection = await amqp.connect(process.env.RABBITMQ_URL!);
const channel = await connection.createChannel();
await channel.assertExchange("events", "topic", { durable: true });
// Publish events
channel.publish("events", "order.created", Buffer.from(JSON.stringify({
orderId: "ORD-456", items: 3,
})));
channel.publish("events", "order.shipped", Buffer.from(JSON.stringify({
orderId: "ORD-456", trackingId: "TRACK-789",
})));
channel.publish("events", "user.signup", Buffer.from(JSON.stringify({
userId: "usr-99", email: "new@user.com",
})));
}
// Subscribe to patterns
async function subscribeToPattern(pattern: string, handler: (data: any, key: string) => void) {
const connection = await amqp.connect(process.env.RABBITMQ_URL!);
const channel = await connection.createChannel();
await channel.assertExchange("events", "topic", { durable: true });
const { queue } = await channel.assertQueue("", { exclusive: true });
await channel.bindQueue(queue, "events", pattern);
channel.consume(queue, (msg) => {
if (!msg) return;
handler(JSON.parse(msg.content.toString()), msg.fields.routingKey);
channel.ack(msg);
});
}
// Subscribe to all order events
await subscribeToPattern("order.*", (data, key) => {
console.log(`Order event [${key}]:`, data);
});
// Subscribe to everything
await subscribeToPattern("#", (data, key) => {
console.log(`[${key}]:`, data);
});
Installation
npm install amqplib
npm install -D @types/amqplib
# RabbitMQ server
docker run -d -p 5672:5672 -p 15672:15672 rabbitmq:management
Best Practices
- Durable queues + persistent messages — Both needed to survive broker restarts; set both always
- Manual ack — Never use
noAck: truein production; explicitly ack after successful processing - Dead letter exchanges — Configure DLX for failed messages; analyze and retry later
- Prefetch — Set
channel.prefetch(N)to limit concurrent processing; prevents consumer overload - Connection pooling — Reuse connections, create channels per operation; connections are expensive
- Topic exchanges — Use
order.*patterns for flexible routing; decouple publishers from consumers - Message TTL — Set
x-message-ttlto prevent queue buildup; stale messages expire automatically - Idempotent consumers — Use
messageIdto deduplicate; messages may be delivered more than once
当前收录版本
1.0.0
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 amqplib 的完整开发指南,涵盖生产者/消费者、Pub/Sub、死信队列等核心模式
- 附带 TypeScript 代码示例和 8 项最佳实践,对 Node.js 微服务开发者具有明确实用价值
亮点
- description 精准描述 amqplib 专家角色及核心能力,触发词覆盖工作队列、发布/订阅、RPC、死信队列等关键场景
待提升项
-
description 内容重复 原报告严重程度:轻微
frontmatter 和 skill_body 开头均包含相同 description 内容
改进建议:建议移除 skill_body 开头的重复 description,保持 frontmatter 唯一性
-
缺少 When to Use 显式章节 原报告严重程度:轻微
文档未设置显式的 When to Use 章节说明适用场景
改进建议:建议在 Installation 前添加 When to Use 章节,明确说明适用开发场景
亮点
- 文档结构清晰,分 Core Capabilities、Installation、Best Practices 等逻辑章节
- frontmatter 完整,包含 name、description、license、compatibility、metadata 等必要字段
亮点
- 代码示例参数配置正确(durable queues、persistent messages、prefetch、DLX)
- 覆盖异常处理机制(try-catch + nack),实现可靠的消息确认流程
- 提供明确的安装命令和 RabbitMQ Docker 启动指令,工具来源清晰
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 142, 143 行
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。