1.1.6 • Published 4 years ago

rabbit-client v1.1.6

Weekly downloads
13
License
MIT
Repository
github
Last release
4 years ago

rabbit-client

RabbitMQ client with implemented reconnection & error handling

Install

$ npm i rabbit-client

Test

$ npm test

API

Constructor

const RabbitClient = require('rabbit-client');

const rabbitClient = new RabbitClient('amqp://localhost:5672', { json: true, appName: 'my-app' });

Pass { json: true } if you want to have JSON.parsed messages in data field of consume callback function.

Get connection

.getConnection()

rabbitClient.getConnection();

Get channel

.getChannel()

const channel = await rabbitClient.getChannel();

await channel.sendToQueue('my-queue', { foo: bar });

You can use objects as content without converting it to Buffer.

Get channel

.getChannel(options)

rabbitClient.getChannel({
  onReconnect: async (channel) => {
    await channel.assertQueue('my-queue');
    await channel.purgeQueue('my-queue');
    await channel.prefetch(10);
    await channel.consume('my-queue', (msg, ch, data) => {
      console.log(data); // parsed json
      ch.ack(msg);
    })
  }
});
1.1.6

4 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago