15.3.2. Connecting via JCA

You can use JCA Message Inflow as an ESB Gateway. To enable a gateway for a service, you must first implement an end-point class that implements the org.jboss.soa.esb.listeners.jca.InflowGateway class:
public interface InflowGateway
{
  public void setServiceInvoker(ServiceInvoker invoker);
}
The end-point class must either have a default constructor or a constructor that takes a ConfigTree parameter. This Java class must also implement the messaging type of the JCA adapter you are binding to. Here's a simple endpoint class example that hooks up to a JMS adapter:
public class JmsEndpoint implements InflowGateway, MessageListener
{
  private ServiceInvoker service;
  private PackageJmsMessageContents transformer = new PackageJmsMessageContents();

  public void setServiceInvoker(ServiceInvoker invoker)
  {
    this.service = invoker;
  }

  public void onMessage(Message message)
  {
    try
    {
      org.jboss.soa.esb.message.Message esbMessage = transformer.process(message);
      service.deliverAsync(esbMessage);
    }
    catch (Exception e)
    {
      throw new RuntimeException(e);
    }
  }
}
One instance of the JmsEndpoint class will be created per gateway defined for this class. This is not like a message-driven bean that is pooled. Only one instance of the class will service each and every incoming message, so you must write thread safe code.
At configuration time, the ESB creates a ServiceInvoker and invokes the setServiceInvoker method on the end-point class. The ESB then activates the JCA end-point and the end-point class instance is ready to receive messages. In the JmsEndpoint example, the instance receives a JMS message and converts into an ESB message. It then uses the ServiceInvoker instance to invoke on the target service.

Note

The JMS end-point class is provided under org.jboss.soa.esb.listeners.jca.JmsEndpoint. You can use this class over and over again with any JMS JCA inflow adapters.