# @keegpt/radonjs

> An event backbone for microservices architectures using express

Latest version **0.1.0** (published 2020-05-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @keegpt/radonjs
pnpm add @keegpt/radonjs
yarn add @keegpt/radonjs
bun add @keegpt/radonjs
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2020-05-16 |
| First published | 2020-05-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 41.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | keegpt |
| Maintainers | josepgomes |

## Links

- npm: https://www.npmjs.com/package/@keegpt/radonjs
- Repository: https://github.com/keegpt/radonjs
- Homepage: https://github.com/keegpt/radonjs#readme
- Issues: https://github.com/keegpt/radonjs/issues
- npm.io page: https://npm.io/package/@keegpt/radonjs

## Dependencies (4)

- [cuid](https://npm.io/package/cuid.md) ^2.1.8
- [express](https://npm.io/package/express.md) ^4.17.1
- [request](https://npm.io/package/request.md) ^2.88.2
- [request-promise](https://npm.io/package/request-promise.md) ^4.2.5

## Recent versions

- 0.1.0 (latest) — 2020-05-16
- 0.0.1-beta.2 — 2020-05-12
- 0.0.1-beta.1 — 2020-05-12
- 0.0.1-beta.0 — 2020-05-12

## README

# RadonJS

An event backbone for microservices architectures using express

Version: Alpha.2

## Installation

Use the package manager [npm](https://www.npmjs.com) to install radonjs.

```bash
npm install @keegpt/radonjs
```

## Server

```js
const radon = require('../lib').default;

(() => {
    const server = new radon.Server();
})();
```

## Clients

```js
const radon = require('../lib').default;

(() => {
    const client = new radon.Client({
        port: 3011,
        onReady: async () => {
            await client.register();

            client.subscribe('test', async (data) => {
                console.log('3011 received:', data);
                return { success: true };
            });

            client.subscribe('another/test', async (data) => {
                console.log('3011 received:', data);
            });
        }
    });
})();
```

```js
const radon = require('../lib').default;

(() => {
    const client = new radon.Client({
        port: 3012,
        onReady: async () => {
            await client.register();

            setTimeout(async () => {
                try {
                    const result = await client.get('test', { some: 'data' });
                    console.log('3012 received', result);

                    client.send('another/test', { more: 'data' });
                } catch (error) {
                    console.error(error)
                }
            }, 1000);
        }
    });
})();
```

## Todo
Some of this are simple to do, i'm just trying to find time :(
* Remove request-promise dependency (use native http/https)
* Allow to customize event timeout and concurrency values
* Create a system to get all updated stats from each event
* A error handling system
* A debug system
* A microservice recovery system
* Implement redis as core

## Docs

### Server options

Property  | Description
------------- | -------------
app  | An express application
path  | Internal radon router path

### Client options

Property  | Description
------------- | -------------
app  | An express application
host | Client host
port | Client port
path | Internal radon router path
serverHost | Server host
serverPort| Server port
serverPath | Server internal radon router path
onReady | Ready to work callback

### Client methods

#### subscribe(eventName, callback)
```js
(() => {
    client.subscribe('EVENT_NAME', async (data: any) => {
        // logic
        // we can return data to the publisher, just returning something in this function
    });
})()
```

#### send(eventName, data)
```js
(() => {
    client.send('EVENT_NAME', { some: 'data' });
})()
```

#### get(eventName, data)
```js
(async () => {
    const result = await client.get('EVENT_NAME', { some: 'data' });
    console.log(result);
})()
```

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

## License
[MIT](https://choosealicense.com/licenses/mit/)

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