AngularJS 1.x service wrapper for the Vert.x Event Bus
Switch branches/tags
canary feature/multiple_connections feature/npm_update greenkeeper-babel-eslint-6.1.0 greenkeeper-babel-loader-6.2.7 greenkeeper-babel-loader-6.2.9 greenkeeper-bower-1.7.5 greenkeeper-bower-1.7.6 greenkeeper-bower-1.7.7 greenkeeper-browserify-13.0.0 greenkeeper-eslint-3.9.0 greenkeeper-eslint-3.9.1 greenkeeper-karma-0.13.16 greenkeeper-karma-0.13.17 greenkeeper-karma-0.13.18 greenkeeper-karma-0.13.19 greenkeeper-karma-browserify-5.0.0 greenkeeper-karma-browserify-5.0.1 greenkeeper-karma-phantomjs-launcher-0.2.3 greenkeeper-karma-phantomjs-launcher-1.0.0 greenkeeper-lodash-4.0.0 greenkeeper-lodash-4.5.1 greenkeeper-lodash-4.16.5 greenkeeper-mocha-2.4.2 greenkeeper-mocha-2.4.3 greenkeeper-phantomjs-2.1.1 greenkeeper-phantomjs-2.1.2 greenkeeper-update-all greenkeeper/babel-eslint-9.0.0 greenkeeper/babel-eslint-10.0.0 greenkeeper/babel-eslint-10.0.1 greenkeeper/babel-loader-8.0.0 greenkeeper/babel-loader-8.0.1 greenkeeper/babel-loader-8.0.2 greenkeeper/babel-loader-8.0.3 greenkeeper/babel-loader-8.0.4 greenkeeper/bower-1.8.3 greenkeeper/bower-1.8.4 greenkeeper/browserslist-4.0.0 greenkeeper/browserslist-4.0.1 greenkeeper/browserslist-4.0.2 greenkeeper/browserslist-4.1.0 greenkeeper/browserslist-4.1.1 greenkeeper/browserslist-4.1.2 greenkeeper/browserslist-4.2.0 greenkeeper/browserslist-4.2.1 greenkeeper/browserslist-4.3.0 greenkeeper/browserslist-4.3.2 greenkeeper/browserslist-4.3.3 greenkeeper/browserslist-4.3.4 greenkeeper/browserslist-4.3.5 greenkeeper/browserslist-4.3.6 greenkeeper/eslint-5.0.0 greenkeeper/eslint-5.0.1 greenkeeper/eslint-loader-2.0.0 greenkeeper/eslint-loader-2.1.0 greenkeeper/eslint-loader-2.1.1 greenkeeper/eslint-plugin-angular-4.0.0 greenkeeper/fbjs-scripts-1.0.0 greenkeeper/fbjs-scripts-1.0.1 greenkeeper/grunt-babel-8.0.0 greenkeeper/grunt-contrib-clean-2.0.0 greenkeeper/jasmine-core-3.1.0 greenkeeper/jasmine-core-3.2.0 greenkeeper/jasmine-core-3.2.1 greenkeeper/jasmine-core-3.3.0 greenkeeper/karma-3.0.0 greenkeeper/karma-3.1.0 greenkeeper/karma-3.1.1 greenkeeper/karma-3.1.2 greenkeeper/karma-3.1.3 greenkeeper/karma-chrome-launcher-2.1.1 greenkeeper/karma-chrome-launcher-2.2.0 greenkeeper/karma-chrome-launcher-pin-2.1.0 greenkeeper/karma-chrome-launcher-pin-2.1.1 greenkeeper/karma-coverage-istanbul-reporter-2.0.0 greenkeeper/karma-coverage-istanbul-reporter-2.0.1 greenkeeper/karma-coverage-istanbul-reporter-2.0.2 greenkeeper/karma-coverage-istanbul-reporter-2.0.3 greenkeeper/karma-coverage-istanbul-reporter-2.0.4 greenkeeper/karma-jasmine-2.0.0 greenkeeper/karma-jasmine-2.0.1 greenkeeper/karma-pin-1.6.0 greenkeeper/karma-sauce-launcher-2.0.0 greenkeeper/karma-sauce-launcher-2.0.1 greenkeeper/karma-sauce-launcher-2.0.2 greenkeeper/karma-webpack-3.0.0 greenkeeper/karma-webpack-3.0.1 greenkeeper/karma-webpack-3.0.2 greenkeeper/karma-webpack-3.0.3 greenkeeper/karma-webpack-3.0.4 greenkeeper/karma-webpack-3.0.5 greenkeeper/load-grunt-tasks-4.0.0 greenkeeper/ng-annotate-webpack-plugin-0.3.0 greenkeeper/update-to-node-10 greenkeeper/webpack-4.0.0 greenkeeper/webpack-4.0.1 greenkeeper/webpack-4.1.0 greenkeeper/webpack-4.1.1 greenkeeper/webpack-4.2.0 greenkeeper/webpack-4.3.0 greenkeeper/webpack-4.4.0 greenkeeper/webpack-4.5.0 greenkeeper/webpack-4.6.0 greenkeeper/webpack-4.7.0 greenkeeper/webpack-4.8.2 greenkeeper/webpack-4.8.3 greenkeeper/webpack-4.9.0 greenkeeper/webpack-4.9.1 greenkeeper/webpack-4.9.2 greenkeeper/webpack-4.10.0 greenkeeper/webpack-4.10.1 greenkeeper/webpack-4.10.2 greenkeeper/webpack-4.11.0 greenkeeper/webpack-4.11.1 greenkeeper/webpack-4.12.0 greenkeeper/webpack-4.12.1 greenkeeper/webpack-4.12.2 greenkeeper/webpack-4.13.0 greenkeeper/webpack-4.14.0 greenkeeper/webpack-4.15.0 greenkeeper/webpack-4.15.1 greenkeeper/webpack-4.16.0 greenkeeper/webpack-4.16.1 greenkeeper/webpack-4.16.2 greenkeeper/webpack-4.16.3 greenkeeper/webpack-4.16.4 greenkeeper/webpack-4.16.5 greenkeeper/webpack-4.17.0 greenkeeper/webpack-4.17.1 greenkeeper/webpack-4.17.2 greenkeeper/webpack-4.17.3 greenkeeper/webpack-4.18.0 greenkeeper/webpack-4.18.1 greenkeeper/webpack-4.19.0 greenkeeper/webpack-4.19.1 greenkeeper/webpack-4.20.0 greenkeeper/webpack-4.20.1 greenkeeper/webpack-4.20.2 greenkeeper/webpack-4.21.0 greenkeeper/webpack-4.22.0 greenkeeper/webpack-4.23.0 greenkeeper/webpack-4.23.1 greenkeeper/webpack-4.24.0 greenkeeper/webpack-4.25.0 greenkeeper/webpack-4.25.1 greenkeeper/webpack-4.26.0 greenkeeper/webpack-4.26.1 greenkeeper/webpack-4.27.0 greenkeeper/webpack-4.27.1 knalli-patch-2 master
Nothing to show
Clone or download
1
Latest commit 3492640 Feb 23, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github chore: relocate github files Mar 4, 2017
build_tools chore(build): add automatic github release scriptlet (fixup) Feb 16, 2017
dist Release 2.4.1 Feb 23, 2018
docs Fixup for badge May 2, 2015
src fix(adapter): fix missing conditional logging Feb 23, 2018
test fix(service): ensure promise wrapped exceptions will be handled Feb 21, 2018
test_scopes feat(tests): add sockjs-client 1.0 and 1.1 as target libraries Mar 8, 2017
.babelrc feat(): switch to babel-preset-env using browserlist (“last 3 versions”) Mar 4, 2017
.bowerrc Use bower non-interactive mode Mar 17, 2014
.codeclimate.yml chore(check): provide code climate Mar 25, 2016
.editorconfig chore(): first version Dec 15, 2013
.eslintignore chore(): improve eslint configuration Mar 25, 2016
.eslintrc chore: update eslint rules (indention) Aug 9, 2017
.gitignore chore: ignore .idea completely Apr 24, 2017
.hound.yml chore(): update houndci config using eslint Mar 25, 2016
.npmignore chore: relocate github files Mar 4, 2017
.nvmrc chore(dev): update dev env to latest Nodejs lts, update locked depend… Feb 17, 2018
.travis.yml chore(travis): fix provisioning chrome for build/test Feb 17, 2018
CHANGELOG.md Release 2.4.1 Feb 23, 2018
CONTRIBUTING.md chore: improve readme/contribution Mar 4, 2017
Gruntfile.js chore(lint): update to eslint 2+ Mar 25, 2016
LICENSE chore(): first version Dec 15, 2013
README.md Apply new credentials for SauceLabs tests Mar 19, 2017
bower.json Merge branch 'feature/vertx_eventbus_3.5.x' into canary Feb 17, 2018
component.json feat(): add AngularJS 1.6 support (fixup) Dec 10, 2016
dependencyci.yml Add config for dependencyci ignoring unlicensed dependencies Aug 21, 2016
karma.conf.js chore(travis): switch to trusty image and ChromeHeadless for Karma Oct 3, 2017
package-lock.json chore(package): update dev dependenies Feb 22, 2018
package.json fix(adapter): fix missing conditional logging Feb 23, 2018
webpack.config.js feat(): switch to babel-preset-env using browserlist (“last 3 versions”) Mar 4, 2017

README.md

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

Branch Stability Status
Canary unstable Build Status
Master stable Build 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.

angular.module('app', ['knalli.angular-vertxbus'])
  .controller('MyCtrl', function(vertxEventBus, vertxEventBusService) {

    // using the EventBus directly
    vertxEventBus.send('my.address', {data: 123});

    // using the service
    vertxEventBusService.send('my.address', {data: 123})

  });

Consume messages

vertxEventBusService.on('myaddress', function(err, message) {
  console.log('Received a message: ', message);
});

Publish a message

vertxEventBusService.publish('myaddress', {data: 123});

Send a message

vertxEventBusService.send('myaddress', {data: 123})
  .then(function(reply) {
    console.log('A reply received: ', reply);
  })
  .catch(function() {
    console.warn('No message');
  });

// The "No reply message found" is controlled via a timeout (default 10000ms)
vertxEventBusService.send('myaddress', {data: 123}, {timeout: 3000})
  .then(function(reply) {
    console.log('A reply received: ', reply);
  })
  .catch(function() {
    console.warn('No message within 3 seconds');
  });

// If the reply is an error, this will be the payload
vertxEventBusService.send('myaddress', {data: 123})
  .then(function(reply) {
    console.log('A reply received: ', reply);
  })
  .catch(function(err) {
    console.warn(err);
  });

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

angular.module('app', ['knalli.angular-vertxbus'])
  .config(function(vertxEventBusProvider) {
    vertxEventBusProvider
      .enable()
      .useReconnect()
      .useUrlServer('http://live.example.org:8888');
  });

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.

// Same as EventBus.registerHandler()
service.registerHandler('myaddress', callback);
service.on('myaddress', callback);
service.addListener('myaddress', callback);

// Same as EventBus.unregisterHandler()
service.unregisterHandler('myaddress', callback);
service.un('myaddress', callback);
service.removeListener('myaddress', callback);

// Same as EventBus.send()
service.send('myaddress', data)

// Same as EventBus.publish
service.publish('myaddress', data)
service.emit('myaddress', data)

// Same as EventBus.readyState()
service.readyState()

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

// Same as EventBus.send() but with a promise
service.send('myaddress', data)
  .then(function(reply) {})
  .catch(function(err) {})

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.