Skip to content

Vertx Resource Adapter Example

Lin Gao edited this page Feb 19, 2016 · 5 revisions

Vert.x is a lightweight application platform for JVM, WildFly is the most popular JavaEE application server, so how they can talk to each other? The answer is the JCA resource adapter. In this document, I will show an example on how to use the Vertx JCA resource adapter to set up a bridge for Vert.x and WildFly to make them understand each other.

Example Overview

The following diagram shows the structure of the example:Vertx JCA resource adapter examples

The whole story is both Vert.x platform and the embedded Vert.x platform within the JCA resource adapter for WildFly start in cluster mode, and use the same cluster configuration to join in the same cluster, then applications can talk to each other by sending/receiving messages via the distributed event bus provided by Vert.x.

NOTE: The example was done using vertx-resource-adapter version: 1.0.2.

How to build the example files?

To build all the example files, what you need to do are the following:

[lgao@localhost sources]$ git clone https://github.com/gaol/vertx-resource-adapter

[lgao@localhost sources]$ cd vertx-resource-adapter

[lgao@localhost vertx-resource-adapter]$ git checkout 1.0.2

[lgao@localhost vertx-resource-adapter]$ ./gradlew clean build -Dexamples -PskipTest

That is all, after the building is completed, you will get the following 4 archives and 1 WildFly CLI script:

  • ra/build/libs/vertx-resource-adapter-1.0.2.rar

This is the main resource adapter archive, the deployment to WildFly will NOT activate since there is no deployment descriptor in it(especially for the jndi binding). User can specify their own configurations in the activation script.

  • build/etc/wildfly-ra-sample.cli

This is the scripts used to activate the resource adapter for WildFly. Users can edit the scripts to add/update configurations before running it.

  • examples/web/build/libs/web-1.0.2.jar

This is a Vert.x module to show a page how the client JavaScript can talk with SockJS Server and MDB

The server side will listen on address: 'sockjs-server-address'

This module will be deployed to Vert.x platform.

  • examples/mdb/build/libs/mdb-1.0.2.jar

This is a Message Driven Bean(MDB) example, which listen on address: 'inbound-address'

This MDB will be deployed to WildFly

  • examples/jsp/build/libs/jsp-1.0.2.war

This is a simple JavaEE web application, which is used to send messages to arbitrary address within the cluster.

This archive will be deployed to WildFly.

How to run the example?

When all needed files are built, follows the steps below to run it:

  1. Vert.x platform runs the module: 'web-1.0.2.jar' in cluster mode:

[lgao@localhost vertx-resource-adapter]$ vertx runzip examples/web/build/libs/web-1.0.2.jar -cluster

  1. Open your web browser, visit http://127.0.0.1:8090, Click the 'Connect' button to register a handler on the sockjs address

  2. Fills some text in Message filed, like: 'hello, sockjs server, I am the client', then click Send to SockJS button.

  3. Starts the WildFly application server using the standalone-full.xml configuration to enable MDB feature

[lgao@localhost wildfly-8.0.0.CR1]$ bin/standalone.sh -c standalone-full.xml

  1. Deploy the vertx-resource-adapter-1.0.2.rar

[lgao@localhost wildfly-8.0.0.CR1]$ bin/jboss-cli.sh --connect --command="deploy ~/sources/vertx-resource-adapter/ra/build/libs/vertx-resource-adapter-1.0.2.rar"

  1. Check ~/sources/vertx-resource-adapter/build/etc/wildfly-ra-sample.cli file to see what needs to be updated, then activate the resource adapter:

[lgao@localhost wildfly-8.0.0.CR1]$ bin/jboss-cli.sh --connect --file=/home/lgao/sources/vertx-resource-adapter/build/etc/wildfly-ra-sample.cli

  1. Deploy the jsp-1.0.2.war archive:

[lgao@localhost wildfly-8.0.0.CR1]$ bin/jboss-cli.sh --connect --command="deploy ~/sources/vertx-resource-adapter/examples/jsp/build/libs/jsp-1.0.2.war"

  1. Open another web browser window, and visit: http://127.0.0.1:8080/jsp-1.0.2/, fills string: sockjs-address to the Address field, and some text in the Message filed, like: 'hello, socjks, this is JSP.', then click Send button

  2. Fills string: sockjs-server-address to the Address field, and some text in the Message filed, like: 'hello, socjks server, this is JSP.', then click Send button

  3. Deploy the mdb-1.0.2.jar archive:

[lgao@localhost wildfly-8.0.0.CR1]$ bin/jboss-cli.sh --connect --command="deploy ~/sources/vertx-resource-adapter/examples/mdb/build/libs/mdb-1.0.2.jar"

  1. In the second web browser window, fills string: inbound-address to the Address field, and some text in the Message filed, like: 'hello, MDB, this is JSP.', then click Send button

  2. In the first web browser window, fills some text in the Message filed, like: 'hello, MDB, this is SockJS Client', then click Send To MDB button.

Where the example source are?

All sources of this example are located at the examples folder of vertx-resource-adapter source tree.

The main files of the example are:

Webinar

See: https://www.youtube.com/watch?v=EtSdUJTv9rY