项目作者: hcsalis

项目描述 :
RxJS powered Event Bus client for Vert.x 3
高级语言: TypeScript
项目地址: git://github.com/hcsalis/vertx3-eventbus-rx-client.git
创建时间: 2017-05-06T19:53:26Z
项目社区:https://github.com/hcsalis/vertx3-eventbus-rx-client

开源协议:MIT License

下载


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:

  1. 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:

  1. npm install vertx3-eventbus-client@3.4.2 --save
  1. npm install rxjs --save

Usage

import as ES module:

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

import as CommonJS module:

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

API

Creating an instance:

  1. // by using factory method
  2. const eb = EventBus.create('server-url');
  3. // by wrapping an existing non-Rxified eventbus object
  4. const eb = new EventBus(delegateEB);

EventBus state:

  1. let ebState;
  2. // get current state
  3. ebState = eb.state;
  4. // get current state and future changes
  5. eb.state$.subscribe(
  6. state => {
  7. ebState = state;
  8. }
  9. );

Sending messages:

  1. const message = {};
  2. // send a message
  3. eb.send('address', message);
  4. // send and expect a reply
  5. eb.rxSend('address', message).subscribe(
  6. reply => {
  7. // received a reply
  8. },
  9. error => {
  10. // received an error
  11. }
  12. );

Message consumer:

  1. // register consumer
  2. const subscription = eb.rxConsumer('address').subscribe(
  3. message => {
  4. // received a message
  5. }
  6. );
  7. // un-register consumer
  8. subscription.unsubscribe();

Getting close event:

  1. // get close event
  2. eb.closeEvent;
  3. // close event is null until State is CLOSED
  4. eb.state$.subscribe(
  5. state => {
  6. if (state !== State.CLOSED) {
  7. console.log(eb.closeEvent); // null
  8. } else {
  9. console.log(eb.closeEvent); // NOT null. Refer to CloseEvent docs on the link below.
  10. }
  11. }
  12. );

Full API documentation can be found HERE.

Testing

Run unit tests with:

  1. 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:

  1. npm run e2e

License

This project is licensed under the MIT License - see the LICENSE file for details