# amqplib-wrapper

> Amqplib wrapper for RabbitMQ

Latest version **1.0.6** (published 2020-03-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install amqplib-wrapper
pnpm add amqplib-wrapper
yarn add amqplib-wrapper
bun add amqplib-wrapper
```

## 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.0.6 |
| Published | 2020-03-21 |
| First published | 2019-09-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | pan1994 |

## Links

- npm: https://www.npmjs.com/package/amqplib-wrapper
- npm.io page: https://npm.io/package/amqplib-wrapper

## Recent versions

- 1.0.6 (latest) — 2020-03-21
- 1.0.5 — 2020-03-21
- 1.0.4 — 2020-01-20
- 1.0.3 — 2020-01-20
- 1.0.2 — 2019-10-04
- 1.0.1 — 2019-10-03
- 0.1.0 — 2019-09-30

## README

# Amqplib-wrapper

This is a simple wrapper module to abstract complexity from [amqplib](https://www.npmjs.com/package/amqplib).

## Usage

```
const amqp = require('amqplib');
const AmqpWrapper = require('./index');

let config = {
  protocol: "amqp",
  hostname: "localhost",
  port: 5672,
  username: "guest",
  password: "guest"
};

let wrapper = new AmqpWrapper(amqp, config);

// Publish
wrapper.publish(exchange, routingKey, message, options)
  .then(() => console.log('sent'));

// Consume with ack
wrapper.consume(queue, prefetch, true, (msg, ack, nack) => {
  let content = msg.content.toString();

  // DO STUFF

  if (condition) {
    ack();
  } else {
    nack();
  }
});

// Consume without ack
wrapper.consume(queue, prefetch, false, msg => {
  let content = msg.content.toString();

  // DO STUFF
});


// Stop consuming from specific queue
wrapper.stopConsuming(queue).then(() => console.log('stopped'));

// Stop consuming from all queues
wrapper.stopConsuming().then(() => console.log('stopped'));

// Purge all messages from queue
wrapper.purge(queue).then(() => console.log('purged'));

// Get number of messages in queue
wrapper.getQueueLength(queue).then(length => console.log(length));

// Check connection
let connected = wrapper.isConnected();

// Close the connection gracefully
wrapper.close().then(() => console.log('closed'));
```

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