egg-amqplib-tf
This module adds AMQP connection manager on the basis of egg-amqplib
Amqp plugin for egg with amqplib, Use connection manager to maintain MQ connection and support automatic reconnection!
Chinese
中文说明
Install
$ npm i egg-amqplib-tf --save
Usage
exports.amqplib = {
enable: true,
package: 'egg-amqplib-tf',
};
Configuration
exports.amqplib = {
client: {
connectOptions: {
protocol: 'amqp',
hostname: 'localhost',
port: 5672,
username: 'guest',
password: 'guest',
locale: 'en_US',
frameMax: 0,
heartbeat: 0,
vhost: '/',
},
},
};
Example
const channelWrapper = await connection.createChannel({
json: true,
setup: (channel) => {
return channel.assertQueue('rxQueueName', {durable: true});
}
});
channelWrapper.sendToQueue('rxQueueName', {hello: 'world'})
.then(function() {
return console.log("Message was sent! Hooray!");
}).catch(function(err) {
return console.log("Message was rejected... Boo!");
});
channelWrapper.addSetup(function(channel) {
return Promise.all([
channel.assertQueue("my-queue", { exclusive: true, autoDelete: true }),
channel.bindQueue("my-queue", "my-exchange", "create"),
channel.consume("my-queue", handleMessage)
])
});
API Document
More instructions here.
Questions & Suggestions
Please open an issue here.
License
MIT