# vertx3-eventbus-rx-client

> RxJS powered Event Bus client for Vert.x 3

Latest version **0.4.2** (published 2017-10-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install vertx3-eventbus-rx-client
pnpm add vertx3-eventbus-rx-client
yarn add vertx3-eventbus-rx-client
bun add vertx3-eventbus-rx-client
```

## 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.4.2 |
| Published | 2017-10-20 |
| First published | 2017-05-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Halil Can Salis |
| Maintainers | salis |
| Keywords | vertx3-eventbus-client, vertx, vert.x, eventbus, client, rxjs, reactive, sockjs, javascript, typescript |

## Links

- npm: https://www.npmjs.com/package/vertx3-eventbus-rx-client
- Repository: https://github.com/hcsalis/vertx3-eventbus-rx-client
- Homepage: https://github.com/hcsalis/vertx3-eventbus-rx-client#readme
- Issues: https://github.com/hcsalis/vertx3-eventbus-rx-client/issues
- npm.io page: https://npm.io/package/vertx3-eventbus-rx-client

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.4.2 (latest) — 2017-10-20
- 0.4.1 — 2017-06-03
- 0.4.0 — 2017-05-15
- 0.3.0 — 2017-05-11

## README

[![Build Status](https://travis-ci.org/hcsalis/vertx3-eventbus-rx-client.svg?branch=master)](https://travis-ci.org/hcsalis/vertx3-eventbus-rx-client)
[![Coverage Status](https://coveralls.io/repos/github/hcsalis/vertx3-eventbus-rx-client/badge.svg?branch=master)](https://coveralls.io/github/hcsalis/vertx3-eventbus-rx-client?branch=master)
[![npm version](https://badge.fury.io/js/vertx3-eventbus-rx-client.svg)](https://badge.fury.io/js/vertx3-eventbus-rx-client)
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)

# vertx3-eventbus-rx-client

[RxJS](http://reactivex.io/rxjs/) powered Event Bus client for [Vert.x 3](http://vertx.io/).

This library: 
- Offers an API similar to Rxified server counterpart.
- Includes Typescript definitions and provides interfaces for data models (Message, CloseEvent etc.).
- Wraps the official client without side effects, thus can be used together with the official client by providing it as a delegate to the constructor.
- Helps to prevent memory leaks by unsubscribing on disconnect or close (or after receiving a reply in case of rxSend).
- Does not provide features like send with timeout, auto-resubscription etc. because these are trivial to implement with rxjs operators and subjects.

## Getting Started

### Installation

install using npm:
```
npm install vertx3-eventbus-rx-client --save
```

### Peer Dependencies

Make sure you have RxJS 5 and official event bus client (version 3.4.x) as dependencies in your project, or install them as follows:
```
npm install vertx3-eventbus-client@3.4.2 --save
```
```
npm install rxjs --save
```

### Usage

import as ES module:
```javascript
import { EventBus } from 'vertx3-eventbus-rx-client';

const eb = EventBus.create('server-address');
```

import as CommonJS module:
```javascript
const RxEB = require('vertx3-eventbus-rx-client');

const eb = RxEB.EventBus.create('server-address');
```

## API
Creating an instance:
```javascript
// by using factory method
const eb = EventBus.create('server-url');

// by wrapping an existing non-Rxified eventbus object
const eb = new EventBus(delegateEB);
```

EventBus state:
```javascript
let ebState;

// get current state
ebState = eb.state;

// get current state and future changes
eb.state$.subscribe(
  state => {
    ebState = state;
  }
);
```

Sending messages:
```javascript
const message = {};
// send a message
eb.send('address', message);

// send and expect a reply
eb.rxSend('address', message).subscribe(
  reply => {
    // received a reply
  },
  error => {
    // received an error
  }
);
```

Message consumer:
```javascript

// register consumer
const subscription =  eb.rxConsumer('address').subscribe(
  message => {
    // received a message
  }
);

// un-register consumer
subscription.unsubscribe();
```

Getting close event:
```javascript

// get close event
eb.closeEvent;

// close event is null until State is CLOSED 
eb.state$.subscribe(
  state => {
    if (state !== State.CLOSED) {
      console.log(eb.closeEvent); // null
    } else {
      console.log(eb.closeEvent); // NOT null. Refer to CloseEvent docs on the link below.
    }
  }
);
```

Full API documentation can be found [HERE](https://hcsalis.github.io/vertx3-eventbus-rx-client/classes/eventbus.html).

## Testing

Run unit tests with:
```
npm run test
```
End-to-end tests should be run against the [Test Server](https://github.com/hcsalis/vertx3-eventbus-rx-client-test-server). Once it is up and running, start the tests with this command:
```
npm run e2e
```
## License

This project is licensed under the MIT License - see the [LICENSE](https://github.com/hcsalis/vertx3-eventbus-rx-client/blob/master/LICENSE) file for details

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