egg-amqplib-plus
v1.1.4
Published
RabbitMq plugin for Egg
Downloads
2
Maintainers
Readme
egg-rabbitmq
amqplib plugin for Egg.js
NOTE: This plugin just for integrate amqplib into Egg.js, more documentation please visit http://www.squaremobius.net/amqp.node/.
Install
$ npm i egg-amqplib-plus --save
Configuration
// {app_root}/config/plugin.js
exports.rabbitmq = {
enable: true,
package: 'egg-amqplib-plus',
};
see config/config.default.js for more detail.
Simple instance
// {app_root}/config/config.default.js
exports.rabbitmq = {
client: {
url: 'amqp://guest:guest@localhost:5672',
},
// load into app, default is open
app: true,
// load into agent, default is close
agent: false,
};
Usage:
(async () => {
// you can access to simple rabbitmq instance channel using app.rabbitmq.
const ch = app.rabbitmq; // Channel
// assertQueue
await ch.assertQueue(queueName, { durable: true });
// checkQueue
await ch.checkQueue(queueName);
// sendToQueue
ch.sendToQueue(queueName, Buffer.from(msg));
}).catch(console.error);
Multiple instance
exports.rabbitmq = {
clients: {
// clientId, access the client instance by app.rabbitmq.get('clientId')
client1: {
url: 'amqp://guest:guest@localhost:5672',
},
client2: {
url: 'amqp://guest:guest@xxx',
},
// ...
},
// load into app, default is open
app: true,
// load into agent, default is close
agent: false,
};
Usage:
const ch1 = app.rabbitmq.get('client1');
const ch2 = app.rabbitmq.get('client2');
Questions & Suggestions
Please open an issue here.