egg-amqp

1.0.2 • Public • Published

egg-amqp

NPM version build status npm download

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.

License

MIT

Package Sidebar

Install

npm i egg-amqp

Weekly Downloads

2

Version

1.0.2

License

MIT

Last publish

Collaborators

  • siubaak