# amqp-rpc-node-client

> amqp node client library

Latest version **0.1.0** (published 2020-08-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install amqp-rpc-node-client
pnpm add amqp-rpc-node-client
yarn add amqp-rpc-node-client
bun add amqp-rpc-node-client
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2020-08-26 |
| First published | 2020-08-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 24.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | celal ertug |
| Maintainers | certug |

## Links

- npm: https://www.npmjs.com/package/amqp-rpc-node-client
- Repository: https://github.com/celalertug/amqp-node-client
- npm.io page: https://npm.io/package/amqp-rpc-node-client

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^8.3.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [amqplib](https://npm.io/package/amqplib.md) ^0.6.0

## Recent versions

- 0.1.0 (latest) — 2020-08-26
- 0.0.9 — 2020-08-18
- 0.0.8 — 2020-08-18
- 0.0.7 — 2020-08-17
- 0.0.6 — 2020-08-15
- 0.0.5 — 2020-08-08
- 0.0.4 — 2020-08-06
- 0.0.3 — 2020-08-05
- 0.0.2 — 2020-08-03
- 0.0.1 — 2020-08-03

## README

## amqp-rpc-node-client

rabbitmq with management ui

```bash
docker run -d --rm --name rabbitmq -p 8080:15672 -p 5672:5672 rabbitmq:3-management
```

rabbitmq standalone

```bash
docker run -d --rm --name rabbitmq -p 5672:5672 rabbitmq:3
```

note : service won't work without rabbitmq

### usage 


`yarn add amqp-rpc-node-client`

simple rpc usage example

```js
const { ServiceCreator } = require('amqp-rpc-node-client');

(async () => {
  const service = await ServiceCreator('localhost', 'hebele-hubele-exchange');

  await service.consume('request.echo', 'worker-queue', async (msg) => {
    const { replyTo, correlationId } = msg.properties;
    const res = service.responseBuilder(200, true, 'ok', JSON.parse(msg.content.toString()));

    if (replyTo) {
      await service.sendToQueue(replyTo, JSON.stringify(res), { correlationId });
    }
  });

  setInterval(async () => {
    const res = await service.rpcRequest('request.echo', JSON.stringify({ value: `surprise ${Date()}` }));
    console.log(JSON.parse(res.content.toString()));
  }, 1000);

  // with reply-to and correlation-id
  setInterval(async () => {
    await service.rpcRequest(
      'request.echo',
      JSON.stringify(
        { value: `surprise ${Date()}` },
      ), 0, ({ replyTo, correlationId }) => {
        console.log('replyTo', replyTo); // replyTo amq.gen-G9lrsEB013fEBOuLgy1hiQ
        console.log('correlationId', correlationId); // correlationId 532de226-ace3-4ead-b859-a314699d45a5
      },
    );
  }, 1000);

  // await service.purgeAndClose();
})();
```

simple consumer example

```js
const assert = require('assert');
const { ServiceCreator } = require('amqp-rpc-node-client');

(async () => {
  const service = await ServiceCreator('localhost', 'hebele-hubele-exchange');

  await service.simpleConsume('simple.math.square', 'simple-math-square', async (msg) => {
    const { value } = JSON.parse(msg);
    return JSON.stringify({ result: value * value });
  });

  let res = await service.rpcRequest('simple.math.square', JSON.stringify({ value: 2 }));
  res = JSON.parse(res.content.toString());
  console.log(res);
  assert.deepStrictEqual(res, { result: 4 });

  await service.close();
})();
```

go example directory for further examples

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