# babex-node

> Babex is a modern solution for communications between microservices.

Latest version **1.0.13** (published 2018-06-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install babex-node
pnpm add babex-node
yarn add babex-node
bun add babex-node
```

## 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.13 |
| Published | 2018-06-13 |
| First published | 2018-04-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 (+4 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | s.pyzhov |
| Keywords | babex |

## Links

- npm: https://www.npmjs.com/package/babex-node
- Repository: https://github.com/spyzhov/babex-node
- Homepage: https://github.com/spyzhov/babex-node#readme
- Issues: https://github.com/spyzhov/babex-node/issues
- npm.io page: https://npm.io/package/babex-node

## Dependencies (2)

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

## Recent versions

- 1.0.13 (latest) — 2018-06-13
- 1.0.12 — 2018-06-06
- 1.0.11 — 2018-06-05
- 1.0.10 — 2018-05-21
- 1.0.9 — 2018-05-17
- 1.0.8 — 2018-04-24
- 1.0.7 — 2018-04-24
- 1.0.6 — 2018-04-23
- 1.0.5 — 2018-04-23
- 1.0.4 — 2018-04-23
- 1.0.3 — 2018-04-23
- 1.0.2 — 2018-04-20
- 1.0.1 — 2018-04-20
- 1.0.0 — 2018-04-20

## README

# About

`Babex` is a modern solution for communications between microservices.

# Versions

## Version 1

Input message:
```
{
  "data": Any,
  "chain": [Path],
  "config": Any
}
```

Where `Path` like:
```
{
  "exchange": String,
  "key": String,
  "isMultiple": Bool,
  "successful": Bool
}
```

# Example

Service example `Sum(a, b)`:

Request:
```json
{
  "data": {
    "a": 2, 
    "b": 3
  },
  "chain": [
    {
      "exchange": "math",
      "key": "math.sum",
      "isMultiple": false
    },
    {
      "exchange": "math",
      "key": "sum.next",
      "isMultiple": false
    }
  ],
  "config": null
}
```

```js
const babex = require('babex-node');
const exchange = 'math';
const routingKey = 'math.sum';
const config = babex.config;
config.name = 'math.sum';
config.address = process.env.RMQ_ADDRESS;

babex
    .newService(config)
    .then((service) => service
        .bindToExchange(exchange, routingKey)
        .then((service) => service
            .listen((message) => {
                let payload = {
                    c: message.data.a + message.data.b
                };
                
                service.next(message, payload);
            })
        )
    )
    .catch(console.warn);
```

Result:
```json
{
  "data": {
    "c": 5
  },
  "chain": [
    {
      "exchange": "math",
      "key": "sum",
      "isMultiple": false,
      "successful": true
    },
    {
      "exchange": "math",
      "key": "sum.next",
      "isMultiple": false,
      "successful": false
    }
  ],
  "config": null
}
```

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