New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

egg-rmq

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-rmq

RabbitMQ egg

latest
Source
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

egg-rmq

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

egg plugin for RabbitMQ

Install

$ npm i egg-rmq --save

Usage

// {app_root}/config/plugin.js
exports.rmq = {
  enable: true,
  package: 'egg-rmq',
};

Configuration

Single Server
// {app_root}/config/config.default.js
exports.rmq = {
    host: 'amqp://localhost',
};
Multiple Server
// {app_root}/config/config.default.js
exports.rmq = {
    servers: {
      test: {
        host: 'amqp://localhost',
      },
    },
  };
// {app_root}/config/config.default.js
// If not set name then this config like Single Server, use app.rmq.conn
exports.rmq = {
    servers: [
      {
        host: 'amqp://localhost',
      },
      {
        name: 'test',
        host: 'amqp://localhost2',
      },
    ],
  };
Route queue

use rmq.route to set Single Server channel

use rmq[server name].route to set Multiple Server channel

// {app_root}/router.js
module.exports = app => {
  const { router, controller, rmq } = app;
  rmq.route('hello', rmq.controller.listener.test); // hello is queue
};
Controller

use ctx.req.ch to get Channel

use ctx.req.queue to get Queue

use app.rmq.conn to get Single Server connect

use app.rmq[server name].conn to get Multiple Server connect

// {app_root}/rmq/controller/hello.js
module.exports = app => {
  return class TestController extends app.Controller {
    async test() {
      const { ctx } = this;
      await ctx.req.ch.assertQueue(ctx.req.queue, { durable: false });
      ctx.req.ch.consume(ctx.req.queue, msg => {
        console.log(' [x] Received %s', msg.content.toString());
        console.log(msg.properties.headers, '#hello headers');
      }, { noAck: true });
      ctx.req.ch.sendToQueue(ctx.req.queue, Buffer.from('Nodejs'), { headers: { user: 'user test' } });
    }
  };
};

see config/config.default.js for more detail.

Questions & Suggestions

Please open an issue here.

License

MIT

Keywords

egg

FAQs

Package last updated on 26 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts