It is a aliyun-amqp tool of Node.js; now, it supports 'work' and 'fanout'. When some errors occurs, it can auto reconnects.
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install aliyun-amqp-tools
const aliConfig = {
accessKeyId: 'xxxxx',
accessKeySecret: 'xxxxx',
resourceOwnerId: 'xxxxx',
host: 'xxxxx'
// 可追加属性
}
const amqpHelper = require('aliyun-amqp-tools')(aliConfig)
const queue = {
name: 'xxxxx',
vhostName: 'xxxxx',
exchange: 'xxxx', // fanout queue is required!
prefetch: 1 // default 1
}
const consumeFuc = async (msg) => {}
await amqpHelper.startProduce(queue, 'work' || 'fanout')
await amqpHelper.startConsume(queue, consumeFuc, 'work' || 'fanout')
await amqpHelper.sendMsg(queue, { anyKey: 'anyValue' }, 'work' || 'fanout')
The API of this module is intended to be similar to the
Node.js aliyun-amqp-node-cli
module.
- queue
queue = {
name: 'xxxxx',
vhostName: 'xxxxx',
exchange: 'xxxx', // fanout queue is required!
prefetch: 1 // default 1
}
- consumeFuc
consumeFuc = async (msg) => {
}
You must init connect before sendMsg.
- role: "Producer" or "Consumer"
- recoverFunc: When amqp reconnect will execute the function.
- recoverFuncArgs: recoverFunc's args
- role: "Producer" or "Consumer"