@eduzz/rabbit
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Eduzz RabbitMQ Client

This is an simplified and padronized RabbitMQ Client for NodeJS

How to use

Create a connection

import { Connection } from '@eduzz/rabbit';

export const myRabbit = new Connection({
  dsn: 'amqp://...',
  exchange: 'my-exchange'
});

Send an message to an topic:

import { myRabbit } from './myRabbit';

const payload = {
  hello: 'world'
};

myRabbit.topic('some.topic').persistent().send({ payload });

Listen to one or multiple topics:

import { myRabbit } from './myRabbit';

myRabbit
  .queue('my.queue')
  .topic('some.topic')
  .topic('another.topic')
  .durable()
  .retryTimeout(60000)
  .listen(async data => {
    console.log(data);
    return true;
  });

Full working demo

import { Connection } from '@eduzz/rabbit';

const connection = new Connection({
  dsn: 'amqp://....',
  exchange: 'theExchange',
  exchangeType: 'topic',
  connectionName: 'my app'
});

// Listening some topic
await connection
  .queue('my.queue')
  .topic('my.topic')
  .durable()
  .retryTimeout(60000)
  .listen<string>(async msg => {
    console.log(msg);
    return true;
  });

// Publishing message
(async () => {
  const publisher = connection.topic('my.topic').persistent();

  setInterval(async () => {
    const payload = {
      number: Math.random() * 1000
    };

    publisher.send({
      payload
    });
  }, 1000);
})();

// Delaying Messages
connection.delayQueue('my.delay.queue').durable().from('from.topic').to('to.topic').timeout(5000).create();

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    138
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    138
  • 0.4.0
    38

Package Sidebar

Install

npm i @eduzz/rabbit

Weekly Downloads

192

Version

1.0.0

License

MIT

Unpacked Size

31 kB

Total Files

22

Last publish

Collaborators

  • luanlmd
  • vitorvmrs
  • miguelaugl
  • danieloprado
  • jonathasprodrigues
  • caferrari