angular-vertxbus

AngularJS 1.x service wrapper for the Vert.x Event Bus
0 people use it
Author: 65389?v=3 knalli

angular-vertxbus

Bower version npm version cdnjs Build Status Sauce Test Status Built with Grunt Greenkeeper badge

Client side library using VertX Event Bus as an Angular Service module

Status

Automatic tests running against the latest version of the major browsers:

Sauce Test Status

How to get

Either download it manually or install it automatically with Bower bower install -D angular-vertxbus or npm npm install -D angular-vertxbus.

Then only import dist/angular-vertxbus.js or dist/angular-vertxbus.min.js. The file itself comes with a CJS header.

Alternatively you can use the cdnjs: cdnjs.com/libraries/angular-vertxbus.

Dependencies

JavaScript (Polyfill)

The source code is written using newer JavaScript (ECMAScript 2015+)and is using the JavaScript transpiler BabelJS.

Depending on your target clients, you probably need to include a browser polyfill (for ES5 clients). BabelJS itself recommends the requirement of its own polyfill. Either you use the explained way using npm modules and/or browserify, or you can use the alternative artifact variant dist/angular-vertxbus.withpolyfill.js.

AngularJS 1.x

This library performs integration tests for AngularJS 1.2 - 1.6!

Vert.x

This library is being developed against the eventbus.js from Vert.x 3.

How to use

API

An Api Documentation is available.

Quick start

You have to define the module dependency, this module is named knalli.angular-vertxbus.

Consume messages

Publish a message

Send a message

Advanced configuration

The module has some advanced configuration options. Perhaps you do not have to change them, but at least you should know them!

Each module configuration option must be defined in the run phase, i.e.:

Please have a look at the API documentation for vertxEventBusProvider and vertxEventBusServiceProvider for further options.

Architecture details

The module contains two items: the stub holder vertxEventBus for the Vert.x EventBus and a more comfortbale high level service vertxEventBusService.

The stub is required because the Vert.x Event Bus cannot handle a reconnect. The reason is the underlaying SockJS which cannot handle a reconnect, too. A reconnect means to create a new instance of SockJS, therefore a new instance of EventBus. The stub ensures only one single instance exists. Otherwise a global module was not possible.

More or less the stub supports the same API calls like the original EventBus.

Based on the stub, the high level service vertxEventBusService detects disconnects, handles reconnects and ensures re-registrations of subscriptions. Furthermore, the service provides some neat aliases for the usage of handlers.

In addition to this, when sending a message with an expected reply:

For each connect or disconnect, a global broadcast will be emitted (on $rootScope with 'vertx-eventbus.system.connected', 'vertx-eventbus.system.disconnected')

Tests

Unit tests

Note: Check that dependencies are be installed (npm install).

The unit tests are available with npm test which is actually a shortcut for grunt test. It performs tests under the current primary target version of AngularJS. Use npm run test-scopes for testing other scoped versions as well.

Local test environment

Note: Check that dependencies are be installed (npm install).

The local test environment starts and utilizes a full Vert.x node and a NodeJS based web server.

Easy: Just run npm run -s start-server and open http://localhost:3000/ in your preferred browser.

If you have changed something, just invoke npm run -s compile in parallel and refresh the browser.

Alternatively:

  1. npm run install-it-vertx-server downloads and installs a Vert.x locally. This will store a cached download artifact at test/e2e//vertx/.
  2. npm run start-it-vertx-server starts an Vert.x on port 8080.
  3. npm run start-it-web-server starts a web server on port 3000.
  4. Ensure at least npm run -s compile has been invoked so there is a dist/angular-vertxbus.js.
  5. Open http://localhost:3000/ in your browser.

License

Copyright 2017 by Jan Philipp. Licensed under MIT.

comments powered by Disqus
This page was last updated 3 months ago.