rabbit-runner

0.0.2 • Public • Published

Rabbit-Runner

Run-Rabbit is a module to connect and handle all messages to a rabbit mq.

Installation

To install this module run:

npm i -save --save-exact run-rabbit

ENV Variables

  • AMQP_HOST: Defines the Host of the mq
  • AMQP_VHOST: Defines the vhost of the mq
  • AMQP_PORT: Defines the Port to connect the mq. Default is 5672
  • AMQP_LOGIN: Defines the login-name for the mq
  • AMQP_PASS: Defines the Password to connect the mq
  • SYSTEM_ID: Defines the name of the System. This value will place in Options of publish

Usage

Start the bus-system

const rabbit = require('run-rabbit');

const options = {
  exchange: {
    options: { type: 'topic', autoDelete: false, durable: true },
    name: 'mqexchange'
  },

  queue: [
    { name: 'user', options: { durable: true, autoDelete: false }},
    { name: 'customer', options: { durable: true, autoDelete: false }}
  ]
}

const connection = rabbit.start(options);

Options

  • exchange:

    • name: Defines the name of the exchange to connect
    • options: Defines the options on connection. (See submodule amqp.exchange)
  • queue: Define all queues to connect in an array

    • name: The name of the queue
    • options: Defines the options on connection. (See submodule amqp.exchange)

Listen on defined queues

.
.
.
const connection = rabbit.start(options);

connection.on('message', (message) => {
  console.log(message);
});

message structure

{
  queue: 'The name of the queue where the message arrive',
  message: {},
  headers: {},
  deliveryInfo: {},
  messageObject: {}
}

Check system connection

To check if the system is connected to the mq, you can run:

.
.
.
const connection = rabbit.start(options);

const isAlive = connection.check(); <<= Returns true when exchange is connected

console.log(isAlive);

Send a message to the exchange

To use this method, you must start the bus system with rabbit.start().

.
.
.
const connection = rabbit.start(options);
const message = { name: 'Wiesmüller', firstname: 'Martin' };
const routingKey = 'test.test';

connection.send(routingKey, message, options); <<= Returns true when exchange is connected

The options object is inherited by the amqp.exchange

Readme

Keywords

none

Package Sidebar

Install

npm i rabbit-runner

Weekly Downloads

1

Version

0.0.2

License

MIT

Last publish

Collaborators

  • mwiesmueller