Skip to content

guoquanwei/aliyun-amqp-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aliyun-amqp-tools

It is a aliyun-amqp tool of Node.js; now, it supports 'work' and 'fanout'. When some errors occurs, it can auto reconnects.

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published