egg-amqplib-plus

1.1.4 • Public • Published

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/.

NPM version build status Test coverage David deps Known Vulnerabilities npm download

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.

License

MIT

Package Sidebar

Install

npm i egg-amqplib-plus

Weekly Downloads

10

Version

1.1.4

License

MIT

Unpacked Size

6.83 kB

Total Files

7

Last publish

Collaborators

  • fuxingzhang