Skip to Main Content U.S. Department of Energy
 

Integrating Enterprise Java Beans Into a MIF Pipeline with an EjbModule

This document describes how to integrate an EJB into a MIF pipeline using JMS. This implementation uses an EjbJmsConnector and a MifEjbModule. The connector makes the Bean accessible via a name bound in JNDI and integrates it into a pipeline using JMS endpoints. The MifEjbModule is similar to a MifModule, except that the implementation is indicated by the JNDI name for the module, as opposed to its full class name.

Outline:

  • Sample code overview
  • How to run the HelloEjb sample
  • Sample code walkthrough

Prerequisites

  • When installing, be sure to include the optional JBoss server: ejb3-clustered.

Sample overview

To create this sample, we modified the HelloComponent from the example in Base Component Model. The resulting HelloEjbComponent contains a single module which accepts the user's name and returns a greeting. A special kind of module – MifEjbModule – is used to integrate the EJB into the pipeline. It is created in a similar way as a regular module except that in this case the JNDI name is specified for the implementation.

Sample code walkthrough

The HelloEjbComponent is constructed similarly to components in the other samples. So, we'll only note the important differences here.

In HelloEjbComponent.configure() we create and add the EJB Module with the following line:

pipeline.addMifEjbModule("HelloNameModule", "HelloEJB", inNameEndp, outGreetEndp);

This will look similar to the method used to add a regular module. The first argument is a name for the module, the second is the implementation and the third and fourth arguments are the inbound and outbound endpoints. Here, we have used class fields for the endpoints so that they can be set via a properties file. Note that the implementation given for this type of module is the JNDI name of the EJB. So, the EJB must be deployed in the application server and bound in JNDI with this name.

In this case, the implementation for this EJB (code listing below) was bound using the EJB3 @RemoteBinding annotation.

@Stateless
@RemoteBinding(jndiBinding="HelloEJB")
public class HelloBean implements HelloInterface 
{
  public String hello(String name)
  {
    String str = "Hello, " + name + ", I'm an EJB";
    return str;
  }
}

Another difference you may notice between this implementation and the implementation for a regular MifMoudule is that this object does not need to implement any MIF-specific interface to be added to a pipeline. Instead, MIF discovers the method to use at run time, matching the incoming data object to a method signature in the bean.

In order to use JMS endpoints with an EJB in a MIF pipeline, we also need to specify an appropriate connector which allows us to use JMS endpoints and lets us access object bound in JNDI. This is done by adding a JmsEjbConnector, which is a JMS connector combined with the JNDI lookup logic. In our example, this is done in HelloEjbComponent.deploy(). The most basic call to create such a connector looks similar to the method to add a JMS connector:

pipeline.addJmsEjbConnector("localhost.connector", jndiUrl);

The first argument is a name to give the connector and the second argument is the address of the JMS server. Additional properties for the underlying JMS connector and JNDI element can be specified by instead using the method:

MifPipeline.addJmsEjbConnector(String name, String jndiUrl, Map<String,Object> jmsProps, Map<String,Object> jndiProps);

This allows you to enter separately properties for JMS and JNDI. For example, you may want to use a separate server URL for JNDI lookups.

 
ejb_modules.txt · Last modified: 2008/05/19 08:55 by adamw