rabbit-client
v1.1.6
Published
RabbitMQ client with implemented reconnection & error handling
Downloads
35
Maintainers
Readme
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);
})
}
});