Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

vertx3-eventbus-rx-client

0.4.2 • Public • Published

Build Status Coverage Status npm version MIT license

vertx3-eventbus-rx-client

RxJS powered Event Bus client for Vert.x 3.

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:

import { EventBus } from 'vertx3-eventbus-rx-client';
 
const eb = EventBus.create('server-address');

import as CommonJS module:

const RxEB = require('vertx3-eventbus-rx-client');
 
const eb = RxEB.EventBus.create('server-address');

API

Creating an instance:

// 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:

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

Sending messages:

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:

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

Getting close event:

 
// 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.

Testing

Run unit tests with:

npm run test

End-to-end tests should be run against the 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 file for details

Install

npm i vertx3-eventbus-rx-client

DownloadsWeekly Downloads

7

Version

0.4.2

License

MIT

Last publish

Collaborators

  • avatar