npm

rabbit-client

1.1.6 • Public • Published

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);
    })
  }
});

Package Sidebar

Install

npm i rabbit-client

Weekly Downloads

3

Version

1.1.6

License

MIT

Unpacked Size

17.9 kB

Total Files

11

Last publish

Collaborators

  • alextolmachevv