
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
amqplib-init
Advanced tools
一个强大且易用的 RabbitMQ 消息队列初始化和管理库,支持自动重连、消息处理、长任务执行等功能。
npm install amqplib-init
const { init } = require('amqplib-init');
// 初始化消息队列
await init({
channelName: 'my-queue',
amqpLink: 'amqp://localhost:5672',
callback: async (message) => {
console.log('收到消息:', message);
await processMessage(message);
}
});
import { init, AMQPInitializer } from 'amqplib-init';
// 方式1: 使用 init 函数
await init({
channelName: 'my-queue',
amqpLink: 'amqp://localhost:5672',
callback: async (message) => {
console.log('收到消息:', message);
}
});
// 方式2: 使用类实例
const initializer = new AMQPInitializer();
await initializer.init({
channelName: 'my-queue',
amqpLink: 'amqp://localhost:5672',
callback: async (message) => {
console.log('收到消息:', message);
}
});
import { init, AmqplibInitOptions } from 'amqplib-init';
const options: AmqplibInitOptions = {
channelName: 'my-queue',
amqpLink: 'amqp://localhost:5672',
prefetch: 10,
callback: async (message: any) => {
console.log('收到消息:', message);
}
};
await init(options);
const { AMQPInitializer } = require('amqplib-init');
const initializer = new AMQPInitializer();
await initializer.init({
channelName: 'my-queue',
amqpLink: 'amqp://localhost:5672',
prefetch: 1,
durable: true,
delay: 1000,
heartbeat: 60,
timeout: 300000,
messageTimeout: 900000,
callback: async (message) => {
// 消息处理逻辑
return processMessage(message);
},
finish: () => {
console.log('初始化完成');
},
initHook: async ({ channel, connection }) => {
// 初始化钩子
console.log('连接已建立');
}
});
// 获取状态信息
console.log(initializer.getStatus());
// 优雅关闭
await initializer.shutdown();
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
channelName | string | 'node-test-channel' | 队列名称 |
amqpLink | string | '' | RabbitMQ 连接地址 |
amqpAutoLink | string | '' | 自动获取连接地址的API |
prefetch | number | 1 | 预取消息数量 |
durable | boolean | true | 队列持久化 |
delay | number | 0 | 消息确认延迟时间(ms) |
heartbeat | number | 60 | 心跳间隔(秒) |
timeout | number | 300000 | 连接超时时间(ms) |
messageTimeout | number | 900000 | 消息处理超时时间(ms) |
reconnectDelay | number | 5000 | 重连延迟时间(ms) |
maxReconnectAttempts | number | 10 | 最大重连次数 |
autoReload | number | 0 | 自动重载间隔(秒) |
callback | function | () => {} | 消息处理回调 |
finish | function | () => {} | 初始化完成回调 |
initHook | function | () => {} | 初始化钩子 |
queryHook | function | () => {} | 查询钩子 |
v1.2.3+ 版本增强了错误处理能力:
// 库会自动处理以下情况:
// - 空消息内容
// - null 或 undefined 消息
// - 无效的 JSON 格式
// - 连接断开重连
const status = initializer.getStatus();
console.log({
isConnected: status.isConnected, // 连接状态
processingCount: status.processingCount, // 处理中消息数量
autoReloaderActive: status.autoReloaderActive, // 自动重载状态
channelName: status.channelName // 当前队列名
});
ISC
欢迎提交 Issue 和 Pull Request!
如果您在使用过程中遇到问题,请通过以下方式获取支持:
demo.jsFAQs
消息队列初始化 - 移除PM2依赖,改用Supervisor管理 (支持15分钟长任务)
The npm package amqplib-init receives a total of 0 weekly downloads. As such, amqplib-init popularity was classified as not popular.
We found that amqplib-init demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.