egg-mq
v0.1.0
Published
egg rabbitmq plugin
Downloads
14
Maintainers
Readme
egg-mq
Install
$ npm i egg-mq --save
Usage
// {app_root}/config/plugin.js
exports.mq = {
enable: true,
package: 'egg-mq',
};
Configuration
// {app_root}/config/config.default.js
const mq = require('./mq.json');
exports.mq = {
rabbitmq: { address, port, username, password },
...mq
};
// {app_root}/config/mq.json
{
"producers": [
{
"exchange": "eggmqproducer.exchange.message",
"exchangeType": "topic"
}
],
"consumers": [
{
"exchange": "eggmqproducer.exchange.message",
"exchangeType": "topic",
"queue": "eggmqconsumer.queue.textMessage",
"topic": "text.*",
"consumer": "foo.bar"
}
]
}
Example
// producer
ctx.service.mq.producer('some.exchange', 'some.topic', payload);
// ctx.service.consumer
async consumer(topic, payload) {
ctx.logger.info(payload);
}
Questions & Suggestions
Please open an issue here.