Version0 /
VertxVert.x is a rich Java-based library with many other language bindings, including JavaScript, that provides an event-driven style of concurrent and distributed programming, a publish-and-subscribed event bus, and a library of communication utilities. Vert.x is developed under the Eclipse foundation and is open source using the Apache 2.0 license. Event BusThe This page covers:
All source files are checked into the Overview and optionsThe Vert.x event bus offers a few different configuration options. Here's a brief overview:
Messages are sent to an address, which can be any string, although a naming scheme is recommended.
"A handler is a thing that receives messages from the bus. You register a handler at an address."
The event bus can be setup to allow traffic only to certain address patterns or message patterns. See the "Server" section for more details. Messaging paradigmsVert.x supports different messaging strategies. All messages are transient. A persistent work queue model can be used to store messages if needed.
Messages are published to an address and delivered to all handlers registered at that address.
Messages are sent to an addresses. One of the handlers registered at that address will receive it, using a round-robin algorithm.
This adds a reply handler to point to point scheme. The sender specifies a reply handler, which the recipient calls upon handling the message. The recipient can again supply a reply handler, which the sender uses. This facilitates a request / response pattern. Client APIThe client API is based on the Vertx event bus bridge library The client requires an implementation of the webSocket module. Note that the implementation may emulate websockets in lieu of supporting true websockets. For example, the SockJS library uses the browser host to establish the connection, and will establish a non-websocket connection if the browser does not support websockets. The Vertx bus client provides the following methods:
The Vertx bus client defines the following methods with no implementation, for callback purposes:
The Vertx bus client provides implementations for these webSocket methods:
It requires these methods from webSocket:
Publish and subscribe accessorsThe latest accessors are in the swarmos repository under:
Each accessor may define inputs and outputs, the initialize(), fire(), and wrapup() methods plus any additional local code. The accessors may be used on any supported host. No changes to the accessor are required. These accessors are written in Javascript. Server-side bus startupA Vert.x instance is needed to host the bus. Code for a simple bus server can be found in the swarmos repository at: This script will start the event bus and bridge (for connecting to non-Vert.x clients) and register a listener at the address To run, install Vert.x, then type: vertx run simpleeventbus.js Messages published to address Browser host clientTogether with a few helper files, the accessor files can be opened with a browser. The latest accessors are in the swarmos repository under: The browser uses the stylesheet To run,
These clients will send messages to and receive messages from any other clients connected to the bus.
Node.js host clientThe Node uses the vertx-eventbus-client package to interface with the bus. This package will be automatically downloaded during the setup step below. To run, 1. Download the swarmos repository and set up Node.js according to the Node.js host instructions.
2. Make sure a Vert.x instance is running somewhere to host the bus. See "Server-side bus startup".
3. The scripts use a URL to locate the accessors. In
/hosts/node , start fileserver.js for a simple file server:
node fileserver.js& 4. The publisher will prompt for user input on stdin. To publish, in
/hosts/node , run pubhost.js :
node pubhost.js 5. The subscriber echoes messages published to address
x on the screen. To subscribe, in a separate command window, in /hosts/node , run subhost.js :
node subhost.js 6. Type q to quit.
7. Kill the file server process by using ps to find the process id, the kill id# to end the process.
Back to Optional JavaScript Modules |