1.0.12 • Published 3 years ago

egg-rabbitmqjs v1.0.12

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

egg-rabbitmq

rabbitmq plugin for egg.js

Install

$ npm i egg-rabbitmqjs --save

Configuration

Multiple Instances

// {app_root}/config/config.default.js
exports.rabbitmq = {
    clients: {
        instance1: {
            url: 'amqp://localhost',
            options: {},
            exchange: {
                name: "xxx",
                type: "direct",
                options: { 
                    durable: true
                },
                bindings: [
                    { queue: "queuename", key: "key", options:{} }
                ],
            },
            deadLetterExchange: {
                name: "xxx",
                type: "direct",
                options: {
                    durable: true
                },
                bindings: [
                    { queue: "queuename", key: "key", options:{} }
                ],
            },
        },
        instance2: {
            url: 'amqp://localhost',
            options: {},
            exchange: {
                name: "xxx",
                type: "direct",
                options: { 
                    durable: true
                },
                bindings: [
                    { queue: "queuename", key: "key", options:{} }
                ],
            },
            deadLetterExchange: {
                name: "xxx",
                type: "direct",
                options: {
                    durable: true
                },
                bindings: [
                    { queue: "queuename", key: "key", options:{} }
                ],
            },
        },
    },
};

Example

configration

config.rabbitmq = {
    clients: {
      producer: {
          url: 'amqp://localhost',
          options: {},
          exchange: {
              name: "EXCHNAGE_NAME",
              type: "direct",
              options: {
                  durable: true
              },
              bindings: [
                  { queue: "QUEUE_NAME", key: "KEY", options: { exclusive: false, durable: true, maxPriority: 10, deadLetterExchange: "DLX_EXCHANGE" } },
              ],
          },
          deadLetterExchange: {
              name: "DLX_EXCHANGE",
              type: "direct",
              options: {
                  durable: true
              },
              bindings: [
                  { queue: "DLX_QUEUE_NAME", key: "KEY", options: { exclusive: false, durable: true, maxPriority: 10, deadLetterExchange: "DLX_EXCHANGE" } },
              ],
          },
      },
    }
  };

Usage

let message = {...};
this.app.rabbitmq.get('producer').publish("EXCHANGE_NAME", message.Key, Buffer.from(JSON.stringify(message)), { priority: message.Priority, persistent: true, mandatory: true });
1.0.12

3 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago