Vertx JCA Adaptor

JCA Resource Adaptor used to communicate between Vert.x and JavaEE application server

License

License

GroupId

GroupId

io.vertx
ArtifactId

ArtifactId

jca-adaptor
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

Vertx JCA Adaptor
JCA Resource Adaptor used to communicate between Vert.x and JavaEE application server
Project URL

Project URL

https://github.com/vert-x/jca-adaptor
Source Code Management

Source Code Management

https://github.com/vert-x/jca-adaptor

Download jca-adaptor

How to add to project

<!-- https://jarcasting.com/artifacts/io.vertx/jca-adaptor/ -->
<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>jca-adaptor</artifactId>
    <version>1.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/io.vertx/jca-adaptor/
implementation 'io.vertx:jca-adaptor:1.0.3'
// https://jarcasting.com/artifacts/io.vertx/jca-adaptor/
implementation ("io.vertx:jca-adaptor:1.0.3")
'io.vertx:jca-adaptor:jar:1.0.3'
<dependency org="io.vertx" name="jca-adaptor" rev="1.0.3">
  <artifact name="jca-adaptor" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.vertx', module='jca-adaptor', version='1.0.3')
)
libraryDependencies += "io.vertx" % "jca-adaptor" % "1.0.3"
[io.vertx/jca-adaptor "1.0.3"]

Dependencies

compile (2)

Group / Artifact Type Version
io.vertx : vertx-hazelcast jar 2.1
io.vertx : vertx-core jar 2.1

test (15)

Group / Artifact Type Version
org.jboss.ironjacamar : ironjacamar-deployers-common jar 1.1.6.Final
org.jboss.ironjacamar : ironjacamar-core-impl jar 1.1.6.Final
org.jboss.ironjacamar : ironjacamar-test-eis jar 1.1.6.Final
org.jboss.ironjacamar : ironjacamar-deployers-fungal jar 1.1.6.Final
org.jboss.ironjacamar : ironjacamar-arquillian-embedded jar 1.1.6.Final
org.jboss.ironjacamar : ironjacamar-common-spi jar 1.1.6.Final
org.jboss.ironjacamar : ironjacamar-embedded jar 1.1.6.Final
io.vertx : vertx-platform jar 2.1
org.jboss.ironjacamar : ironjacamar-common-impl jar 1.1.6.Final
org.jboss.ironjacamar : ironjacamar-core-api jar 1.1.6.Final
org.jboss.ironjacamar : ironjacamar-arquillian-embedded-byteman jar 1.1.6.Final
org.jboss.ironjacamar : ironjacamar-depchain jar 1.1.6.Final
org.jboss.ironjacamar : ironjacamar-common-api jar 1.1.6.Final
junit : junit jar 4.10
org.jboss.ironjacamar : ironjacamar-validator jar 1.1.6.Final

Project Modules

There are no modules declared in this project.

Vert.x 2.x is deprecated - use instead http://vertx.io

JCA Resource Adaptor for Vert.x

JCA Adaptor for Vertx to interaction between JavaEE application server and Vertx cluster.

Overview

The idea of the resource adapter is try to start an embedded Vertx within the JavaEE application server, then expose the Vertx distributed event bus and shared data as JCA components.

It supports both outbound and inbound vertx communication.

Maven Dependency

Maven dependency of this adapter:

  <dependency>
    <groupId>io.vertx</groupId>
    <artifactId>jca-adaptor</artifactId>
    <version>1.0.3</version>
  </dependency>
  <dependency>
    <groupId>io.vertx</groupId>
    <artifactId>jca-adaptor</artifactId>
    <version>1.0.3</version>
    <type>rar</type>
  </dependency>

Outbound communication

An application component like a web application(a .war), an ejb instance can send message to the Vertx cluster using outbound communication.

Typical usage is try to get the org.vertx.java.resourceadapter.VertxConnectionFactory using a JNDI lookup, or inject the resource using CDI, then gets one org.vertx.java.resourceadapter.VertxConnection instance, then you can get the Vertx EventBus to send messages.

javax.naming.InitialContext ctx = null;
org.vertx.java.resourceadapter.VertxConnection conn = null;
try
{
   ctx = new javax.naming.InitialContext();
   org.vertx.java.resourceadapter.VertxConnectionFactory connFactory = 
   (org.vertx.java.resourceadapter.VertxConnectionFactory)ctx.lookup("java:/eis/VertxConnectionFactory");
   conn = connFactory.getVertxConnection();
   conn.eventBus().send("outbound-address", "Hello from JCA");
}
catch (Exception e)
{
   e.printStackTrace();
}
finally
{
   if (ctx != null)
   {
      ctx.close();  
   }
   if (conn != null)
   {
      conn.close();  
   }
}
  • NOTE: always call org.vertx.java.resourceadapter.VertxConnection.close() when you does not need the connection anymore, otherwise the connection pool will be full very soon.

Inbound communication

Usually a MDB is the client which receives inbound communication from a Vert.x cluster.

The end point of the MDB implements interface: org.vertx.java.resourceadapter.inflow.VertxListener.

package org.vertx.java.ra.examples.mdb;

import org.vertx.java.resourceadapter.inflow.VertxListener;
import org.vertx.java.core.eventbus.Message;

import java.util.logging.Logger;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;

import org.jboss.ejb3.annotation.ResourceAdapter;


@MessageDriven(name = "VertxMonitor", 
       messageListenerInterface = VertxListener.class,
       activationConfig = {
                   @ActivationConfigProperty(propertyName = "address", propertyValue = "inbound-address"),
                   @ActivationConfigProperty(propertyName = "clusterHost", propertyValue = "localhost"),
                   @ActivationConfigProperty(propertyName = "clusterPort", propertyValue = "0"),
                   })
@ResourceAdapter("jca-adaptor-1.0.3.rar")
public class VertxMonitor implements VertxListener {

   private Logger logger = Logger.getLogger(VertxMonitor.class.getName());
   
    /**
     * Default constructor. 
     */
    public VertxMonitor() {
        logger.info("VertxMonitor started.");
    }

   @Override
   public  void onMessage(Message message)
   {
      logger.info("Get a message from Vert.x at address: " + message.address());
      T body = message.body();
      if (body != null)
      {
         logger.info("Body of the message: " + body.toString());
      }
   }
}

Now, you can send a message in your Vert.x runtime to address: inbound-address, and the MDB will get notified.

Configuration

The configuration of outbound and inbound are almost the same, they are:

  • clusterHost
    • Type: java.lang.String
    • Outbound / Inbound
    • clusterHost specifies which network interface the distributed event bus will be bound to. Default to localhost.
  • clusterPort
    • Type: java.lang.Integer
    • Outbound / Inbound
    • clusterPort specifies which port the distributed event bus will be bound to. Default to 0, means random available port.
  • clusterConfigFile
    • Type: java.lang.String
    • Outbound / Inbound
    • clusterConfigFile specifies which cluster file will be used to join the vertx cluster. default-cluster.xml shipped with the resource adapter will be used if it is not specified. It can be either a file absolute path, or a system property using expression like: '${cluster.config.file}'. The resource adapter ships a 'default-cluster.xml' inside the .rar file, which will join a multicast network
  • timeout
    • Type: java.lang.Long
    • Outbound / Inbound
    • timeout specifies the milliseconds timeout waiting for the Vert.x starts up. Default to 30000, 30 seconds.
  • address
    • Type: java.lang.String
    • Inbound Only
    • Not null
    • address specifies in which vertx event bus address the Endpoint(MDB) listen.

Credits to IronJacamar

IronJacamar is the top lead JCA implementation in the industry, it supports JCA 1.0/1.5/1.6/1.7, and is adopted by WildFly application server.

This resource adapter uses IronJacamar as the development and test environment.

Building

It uses gradle for the building, change your current working directory to the codes, then run the command:

./gradlew clean rar

It will generate the resource adapter file (.rar file) in the ra/build/libs/ directory.

If you want to build the examples, run the command:

./gradlew clean build -Dexamples

Deploy to Wildfly

Follow the steps below to deploy the resource adapter to WildFly application server:

  • Build it from source or download from the Bintary

  • Starts the WildFly application server.

WILDFLY-HOME/bin/standalone.sh -c standalone-full.xml

  • Deploy the .rar file

WILDFLY-HOME/bin/jboss-cli.sh --connect --command="deploy ra/build/libs/jca-adaptor-1.0.3.rar" WILDFLY-HOME/bin/jboss-cli.sh --connect --file=build/etc/wildfly-ra-sample.cli

Jenkins

Build on CloudBees

Downloads

You can download the resouce adapter from: Bintary

Examples

For examples, please refer to this document

If you get any issues or suggestions, you are appreciated to share the idea by firing an issue here

Have fun!

io.vertx

vert.x

Legacy Vert.x 2.x - use instead Vert.x 3 instead https://github.com/eclipse/vert.x

Versions

Version
1.0.3
1.0.3.Beta1