# rabbit-client

> RabbitMQ client with implemented reconnection & error handling

Latest version **1.1.6** (published 2020-06-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install rabbit-client
pnpm add rabbit-client
yarn add rabbit-client
bun add rabbit-client
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2020-06-16 |
| First published | 2019-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 17.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alexander Tolmachev |
| Maintainers | alextolmachevv |
| Keywords | message-queue, rabbit-mq, rabbitmq, amqplib, amqp |

## Links

- npm: https://www.npmjs.com/package/rabbit-client
- Repository: https://github.com/AlexTolmachev/rabbit-client
- Homepage: https://github.com/AlexTolmachev/rabbit-client#readme
- Issues: https://github.com/AlexTolmachev/rabbit-client/issues
- npm.io page: https://npm.io/package/rabbit-client

## Dependencies (2)

- [amqplib](https://npm.io/package/amqplib.md) ^0.5.6
- [node-cleanup](https://npm.io/package/node-cleanup.md) ^2.1.2

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 1.1.6 (latest) — 2020-06-16
- 1.1.5 — 2019-06-25
- 1.1.4 — 2019-06-25
- 1.1.3 — 2019-06-23
- 1.1.2 — 2019-06-21
- 1.1.1 — 2019-06-21

## README

# rabbit-client

RabbitMQ client with implemented reconnection & error handling

## Install
```shell
$ npm i rabbit-client
```

## Test
```shell
$ npm test
```

## API

### Constructor
```js
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()
```js
rabbitClient.getConnection();
```

### Get channel
#### .getChannel()
```js
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)
```js
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);
    })
  }
});
```

---
_Source: https://npm.io/package/rabbit-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
