egg-amqp
v1.0.2
Published
Amqp for Egg.js
Downloads
4
Maintainers
Readme
egg-amqp
Amqp client for egg framework with amqplib.
Install
$ npm i egg-amqp --save
Usage
// {app_root}/config/plugin.js
exports.amqp = {
enable: true,
package: 'egg-amqp',
};
Configuration
// {app_root}/config/config.default.js
exports.amqp = {
protocol: 'amqp',
hostname: 'localhost',
port: 5672,
username: 'guest',
password: 'guest',
vhost: '/',
// opts: {},
};
see config/config.default.js for more detail.
Example
Produce
const ch = yield app.amqp.createChannel();
yield ch.assertQueue('test');
ch.sendToQueue(queue, new Buffer('hello world'));
Consume
const ch = yield app.amqp.createChannel();
yield ch.assertQueue('test');
const msg = yield new Promise(resolve => ch.consume(queue, msg => resolve(msg)));
ch.ack(msg);
console.log(msg.content.toString()); // hello world
Questions & Suggestions
Please open an issue here.