# amqp.node.client

> AMQP(Advanced Message Queue Protocol) Client of Node.js

Latest version **1.1.5** (published 2018-09-21) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install amqp.node.client
pnpm add amqp.node.client
yarn add amqp.node.client
bun add amqp.node.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.5 |
| Published | 2018-09-21 |
| First published | 2018-06-04 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | guanbo |
| Maintainers | guanbo |
| Keywords | amqp, rabbitmq, node.js |

## Links

- npm: https://www.npmjs.com/package/amqp.node.client
- Homepage: https://github.com/guanbo/amqpclient
- npm.io page: https://npm.io/package/amqp.node.client

## Dependencies (1)

- [amqplib](https://npm.io/package/amqplib.md) ^0.5.2

## Recent versions

- 1.1.5 (latest) — 2018-09-21
- 1.1.4 — 2018-09-21
- 1.1.3 — 2018-09-19
- 1.1.2 — 2018-07-25
- 1.1.1 — 2018-07-11
- 1.1.0 — 2018-07-11
- 1.0.1 — 2018-06-04
- 1.0.0 — 2018-06-04

## README

# AMQP Client
[![Build Status](https://travis-ci.org/guanbo/amqpclient.svg?branch=master)](https://travis-ci.org/guanbo/amqpclient)

An AMQP Client of Node.js base on amqplib with auto reconnect

## Quick Start

### Consumer 

```js
const AMQPClient = require('amqp.node.client');
const consumer = new AMQPClient({}, 1000);

const q = 'amqpclient.test';

consumer.start((ch) => {
  return ch.assertQueue(q).then(ok => {
    return ch.consume(q, (msg) => {
      msg.should.be.Object();
      if (msg) {
        let body = msg.content.toString();
        console.log(body);
        ch.ack(msg);
      }
    });
  });
});
```

### Disconnect

```shell
$ rabbitmqctl close_all_connections test_reconnect_case
```

### Producer 

```js
const AMQPClient = require('amqp.node.client');
const consumer = new AMQPClient();

const q = 'amqpclient.test';
const message = 'test message';

producer.start(ch => {
  ch.assertQueue(q).then(ok => {
    ch.sendToQueue(q, Buffer.from(message));
  });
});
```

## RPC
### Server

```js
/**
 * @name rpcServer
 * @param  {function} srv must return Promise Object;
 * @param  {object} rpcOptions optional
 */
rpcServer.rpcService(opts=>{
  const res = parseInt(opts.a)+parseInt(opts.b);
  return Promise.resolve({val: res});
}, {queue: 'my.custom.rpc.request.queue.name'}).then(res=>{
  console.log('rpc server ready');
});
```

### Client

```js
rpcClient.rpc({a:1, b:2}, {queue: q}).then(res=>{
  res.val.should.be.equal(3);
});
```

## Environment
- `RABBITMQ_HOST`   default host if set
- `RABBITMQ_VHOST`  default vhost if set
- `RABBITMQ_USER`   default username if set
- `RABBITMQ_PWD`    default password if set
- `RABBITMQ_PORT`   default port if set

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