0.0.5 • Published 3 years ago

aliyun-amqp-tools v0.0.5

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

amqp-tools

just support ES6

Install

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install aliyun-amqp-tools

Example

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')

API

The API of this module is intended to be similar to the Node.js aliyun-amqp-node-cli module.

startProduce(queue, type)

  • queue
queue = {
    name: 'xxxxx',
    vhostName: 'xxxxx',
    exchange: 'xxxx', // fanout queue is required!
    prefetch: 1 // default 1
}

startConsume(queue, consumeFuc, type)

  • consumeFuc
consumeFuc = async (msg) => {

}

sendMsg(queue, msgObj || msgArray, type)

You must init connect before sendMsg.

getConn(vhostName, role, recoverFunc, recoverFuncArgs)

  • role: "Producer" or "Consumer"
  • recoverFunc: When amqp reconnect will execute the function.
  • recoverFuncArgs: recoverFunc's args

closeConn(vhostName, role)

  • role: "Producer" or "Consumer"

Licence

MIT