Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Latest commit

 

History

History
116 lines (83 loc) · 3.46 KB

vertx.adoc

File metadata and controls

116 lines (83 loc) · 3.46 KB

Vert.x

This fraction adds support for the Vert.x API in Java EE applications by enabling the Vert.x JCA adapter.

Configuration

<dependency>
  <groupId>org.wildfly.swarm</groupId>
  <artifactId>vertx</artifactId>
</dependency>

Usage

There is no need to configure the VertxFraction if you intend to use the default behavior (JCA adapter deployed and VertxConnectionFactory registered).

Using the Java API you can inhibit the JCA adapter deployment (if you intend to use just the Vert.x APIs for example).

swarm.fraction(new VertxFraction()
               .inhibitAdapterDeployment()
);

You can also modify the VertxConnectionFactory parameters using the same API

swarm.fraction(new VertxFraction()
               .jndiName("java:/eis/MyVertxConnectionFactory")
               .clusterHost("myhost")
               .clusterPort(1000)
);

Overview

The general purpose of a JCA resource adapter is to provide connectivity to an Enterprise Information System (EIS) from a Java EE application server. Specifically, the Vert.x JCA adapter provides both outbound and inbound connectivity with a Vert.x instance.

Outbound Connectivity

An application component (e.g Servlet, EJB), can send messages to a Vert.x instance.

Usage:

@Resource(mappedName="java:/eis/VertxConnectionFactory")
VertxConnectionFactory connFactory;

public void sendMessage() throws Exception {
    try (VertxConnection conn = connFactory.getVertxConnection()) {
        conn.vertxEventBus().send("tacos", "Hello from JCA");
    }
}
Important
As with any JCA resource, always call the close() method (or use the try-with-resources strategy above) when your work is complete to allow the connection to be returned to the pool. This will not close the underlying Vert.x instance. Please see the JCA specification for more details.

Inbound Connectivity

Since the JCA 1.5 specification, inbound connectivity is provided via a listener interface which can be implemented by a Java EE Message Driven Bean (MDB). As opposed to the default JMS listener type, the Vert.x JCA listener interface allows an MDB to receive messages from a Vert.x address.

The endpoint of the MDB should implement io.vertx.resourceadapter.inflow.VertxListener.

package io.vertx.resourceadapter.examples.mdb;

import io.vertx.resourceadapter.inflow.VertxListener;
import io.vertx.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 = "tacos")
})
@ResourceAdapter("vertx-ra")
public class VertxMonitor implements VertxListener {

   private static final Logger logger = Logger.getLogger(VertxMonitor.class.getName());

    /**
     * Default constructor.
     */
    public VertxMonitor() {
        logger.info("VertxMonitor started.");
    }

   @Override
   public <T> void onMessage(Message<T> message) {
      logger.info("Got a message from Vert.x at address: " + message.address());

      T body = message.body();

      if (body != null) {
         logger.info("Body of the message: " + body.toString());
      }
   }
}