0.4.2 • Published 8 years ago
vertx3-eventbus-rx-client v0.4.2
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 --savePeer 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 --savenpm install rxjs --saveUsage
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 testEnd-to-end tests should be run against the Test Server. Once it is up and running, start the tests with this command:
npm run e2eLicense
This project is licensed under the MIT License - see the LICENSE file for details