6 Configuring JMS Adapters

This section contains information on the following subjects:

6.1 Overview of JMS Adapter Configuration

Oracle CEP provides two Java Message Service (JMS) adapters that you can use in your event applications to send and receive messages to and from a JMS queue, respectively, without writing any Java code.

The built-in JMS adapter supports the following modes of operation:

Oracle CEP supports the following JMS providers:

  • Oracle WebLogic JMS

  • TIBCO EMS JMS

Oracle CEP includes a WebLogic JMS client. When connecting to Oracle WebLogic server, Oracle CEP uses the T3 client by default. You can use the IIOP WebLogic client by starting Oracle WebLogic Server with the -useIIOP command-line argument. This is a server-wide setting that is independent of the JMS code being used (whether it is one of the provided adapters or custom JMS code). It is not possible to mix T3 and IIOP usage within a running Oracle CEP server.

If you are using a JMS provider other than WebLogic JMS, such as TIBCO, you must include the appropriate client jar as a library within your application jar.

For general information about JMS, see Java Message Service on the Sun Developer Network at http://java.sun.com/products/jms/.

6.1.1 Inbound JMS

The inbound JMS adapter receives messages from a JMS queue and automatically converts them into events by matching property names with a specified event type. Typically, you also customize this conversion by writing your own Java class to specify exactly how you want the incoming JMS messages to be converted into one or more event types.

If you do not provide your own converter class, and instead let Oracle CEP take care of the conversion between messages and event types, the following is true:

  • You must specify an event type that Oracle CEP uses in its conversion. See Section 6.2.3, "Configuring the JMS Adapters" for details.

  • By default, the inbound JMS adapter default converter expects incoming JMS messages to be of type MapMessage. For each incoming message, an event of the specified event type is created. For each map element in the incoming message, the adapter looks for a property on the event-type and if found, sets the corresponding value.

For more information, see Section 6.1, "Overview of JMS Adapter Configuration".

6.1.2 Outbound JMS

The outbound JMS adapter sends events to a JMS queue, automatically converting the event into a JMS map message by matching property names with the event type. Typically, you also customize this conversion by writing your own Java class to specify exactly how you want the event types to be converted into outgoing JMS messages.

If you do not provide your own converter class, and instead let Oracle CEP take care of the conversion between messages and event types, the following is true:

  • You must specify an event type that Oracle CEP uses in its conversion. See Section 6.2.3, "Configuring the JMS Adapters" for details.

  • By default, the outbound JMS adapter default converter creates JMS messages of type MapMessage. For each property of the event, a corresponding element is created in the output MapMessage.

For more information, see Section 6.1, "Overview of JMS Adapter Configuration".

6.2 Using JMS Adapters

The following procedure describes the typical steps to use the JMS adapters provided by Oracle CEP.

Note:

It assumed in this section that you have already created an Oracle CEP application along with its EPN assembly file and component configuration files, and that you want to update the application to use an inbound or outbound JMS adapter. If you have not, refer to Chapter 1, "Overview of Creating Oracle CEP Applications" for details.

To use JMS adapters:

  1. Optionally create a converter Java class if you want to customize the way JMS messages are converted into event types, or vice versa in the case of the outbound JMS adapter. This step is optional because you can let Oracle CEP make the conversion based on mapping property names between JMS messages and a specified event type.

    See Section 6.2.1, "Creating a Custom Converter Between JMS Messages and Event Types."

  2. Update the EPN assembly file of the application by adding a <wlevs:adapter> tag for each inbound and outbound JMS adapter you want to use in your application.

    See Section 6.2.2, "Updating the EPN Assembly File With JMS Adapters."

  3. Configure the JMS properties of the JMS adapter by updating the component configuration file.

    See Section 6.2.3, "Configuring the JMS Adapters."

  4. Update the MANIFEST.MF file of your application to adding the following packages to the Import-Package header:

    Import-Package: com.bea.core.encryption,com.bea.wlevs.adapters.jms.api,
        ...
    

6.2.1 Creating a Custom Converter Between JMS Messages and Event Types

If you want to customize the way a JMS message is converted to an event type, or vice versa, you must create your own converter bean.

The custom converter bean for an inbound JMS must implement the com.bea.wlevs.adapters.jms.api.InboundMessageConverter interface. This interface has a single method:

public List convert(Message message) throws MessageConverterException, JMSException;

The message parameter corresponds to the incoming JMS message and the return value is a List of events that will be passed on to the next stage of the event processing network.

The custom converter bean for an outbound JMS must implement the com.bea.wlevs.adapters.jms.api.OutboundMessageConverter interface. This interface has a single method:

public List<Message> convert(Session session, Object event) throws MessageConverterException, JMSException;

The parameters correspond to an event received by the outbound JMS adapter from the source node in the EPN and the return value is a List of JMS messages.

See the Oracle CEP Java API Reference for a full description of these APIs.

The following example shows the Java source of a custom converter bean that implements both InboundMessageConverter and OutboundMessageConvert; this bean can be used for both inbound and outbound JMS adapters:

package com.customer;
import com.bea.wlevs.adapters.jms.api.InboundMessageConverter;
import com.bea.wlevs.adapters.jms.api.MessageConverterException;
import com.bea.wlevs.adapters.jms.api.OutboundMessageConverter;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import java.util.ArrayList;
import java.util.List;
public class MessageConverter implements InboundMessageConverter, OutboundMessageConverter {
    public List convert(Message message) throws MessageConverterException, JMSException {
        TestEvent event = new TestEvent();
        TextMessage textMessage = (TextMessage) message;
        event.setString_1(textMessage.getText());
        List events = new ArrayList(1);
        events.add(event);
        return events;
    }
    public List<Message> convert(Session session, Object inputEvent) throws MessageConverterException, JMSException {
        TestEvent event = (TestEvent) inputEvent;
        TextMessage message = session.createTextMessage(
            "Text message: " + event.getString_1()
        );
        List<Message> messages = new ArrayList<Message>();
        messages.add(message);
        return messages;
    }
}

6.2.2 Updating the EPN Assembly File With JMS Adapters

For each JMS adapter in your event processing network, you must add a corresponding <wlevs:adapter> tag to the EPN assembly file of your application; use the provider attribute to specify whether the JMS adapter is inbound or outbound. Follow these guidelines:

  • If you are specifying an inbound JMS adapter, set the provider attribute to jms-inbound, as shown:

    <wlevs:adapter id="jmsInbound" provider="jms-inbound"/>
    

    The value of the id attribute, in this case jmsInbound, must match the name specified for this JMS adapter in its configuration file. The configuration file configures the JMS queue from which this inbound JMS adapter gets its messages.

    Because no converter bean is specified, Oracle CEP automatically converts the inbound message to the event type specified in the component configuration file by mapping property names.

  • If you are specifying an outbound JMS adapter, set the provider attribute to jms-outbound, as shown:

    <wlevs:adapter id="jmsOutbound" provider="jms-outbound"/>
    

    The value of the id attribute, in this case jmsOutbound, must match the name specified for this JMS adapter in its configuration file. The configuration file configures the JMS queue to which this outbound JMS adapter sends messages.

    Because no converter bean is specified, Oracle CEP automatically converts the incoming event types to outgoing JMS messages by mapping the property names.

  • For both inbound and outbound JMS adapters, if you have created a custom converter bean to customize the conversion between the JMS messages and event types, first use the standard <bean> Spring tag to declare it in the EPN assembly file. Then pass a reference of the bean to the JMS adapter by specifying its id using the <wlevs:instance-property> tag, with the name attribute set to converterBean, as shown:

    <bean id="myConverter"
          class="com.customer.MessageConverter"/>
    
    <wlevs:adapter id="jmsOutbound" provider="jms-outbound">  
        <wlevs:instance-property name="converterBean" ref="myConverter"/>
    </wlevs:adapter>
    

    In this case, be sure you do not specify an event type in the component configuration file because it is assumed that the custom converter bean takes care of specifying the event type.

As with any other stage in the EPN, add listeners to the <wlevs:adapter> tag to integrate the JMS adapter into the event processing network. Typically, an inbound JMS adapter is the first stage in an EPN (because it receives messages) and an outbound JMS adapter would be in a later stage (because it sends messages). However, the requirements of your own Oracle CEP application define where in the network the JMS adapters fit in.

The following sample EPN assembly file shows how to configure an outbound JMS adapter. The network is simple: a custom adapter called getData receives data from some feed, converts it into an event type and passes it to myProcessor, which in turn sends the events to the jmsOutbound JMS adapter via the streamOne channel. Oracle CEP automatically converts these events to JMS messages and sends the messages to the JMS queue configured in the component configuration file associated with the jmsOutbound adapter.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd
  http://www.bea.com/ns/wlevs/spring
  http://www.bea.com/ns/wlevs/spring/spring-wlevs-v11_1_1_3.xsd">
    <wlevs:event-type-repository>
        <wlevs:event-type type-name="JMSEvent">
            <wlevs:class>com.customer.JMSEvent</wlevs:class>
        </wlevs:event-type>
    </wlevs:event-type-repository>
    <!-- Custom adapter that gets data from somewhere and sends it to myProcessor -->
    <wlevs:adapter id="getData" 
                   class="com.customer.GetData">
        <wlevs:listener ref="myProcessor"/>
    </wlevs:adapter>
    <wlevs:processor id="myProcessor" />
    <wlevs:adapter id="jmsOutbound" provider="jms-outbound"/>
     <!-- Channel for events flowing from myProcessor to outbound JMS adapter -->
    <wlevs:channel id="streamOne">
       <wlevs:listener ref="jmsOutbound"/>
       <wlevs:source ref="myProcessor"/>
    </wlevs:channel>
</beans>

The following sample EPN assembly file shows how to configure an inbound JMS adapter. The network is simple: the inbound JMS adapter called jmsInbound receives messages from the JMS queue configured in its component configuration file. The Spring bean myConverter converts the incoming JMS messages into event types, and then these events flow to the mySink event bean.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd
  http://www.bea.com/ns/wlevs/spring
  http://www.bea.com/ns/wlevs/spring/spring-wlevs-v11_1_1_3.xsd">
    <wlevs:event-type-repository>
        <wlevs:event-type type-name="JMSEvent">
            <wlevs:class>com.customer.JMSEvent</wlevs:class>
        </wlevs:event-type>
    </wlevs:event-type-repository>
    <!-- Event bean that is an event sink -->
    <wlevs:event-bean id="mySink" 
                      class="com.customer.MySink"/>
    <!-- Inbound JMS adapter with custom converter class; adapter sends events to mySink event bean-->
   <bean id="myConverter" class="com.customer.MessageConverter"/>
   <wlevs:adapter id="jmsInbound" provider="jms-inbound">
       <wlevs:instance-property name="converterBean" ref="myConverter"/>
       <wlevs:listener ref="mySink"/>
    </wlevs:adapter>
</beans>

6.2.3 Configuring the JMS Adapters

You configure the JMS adapters in their respective configuration files, similar to how you configure other components in the event processing network, such as processors or streams. For general information about these configuration files, see Section 1.1.5, "Component Configuration Files."

The root element for configuring a JMS adapter is jms-adapter. The name child element for a particular adapter must match the id attribute of the corresponding wlevs:adapter element in the EPN assembly file that declares this adapter.

Table 6-1 describes the additional child elements of jms-adapter you can configure for both inbound and outbound JMS adapters.

Table 6-1 Child Elements of jms-adapter for Inbound and Outbound Adapters

Child Element Description

event-type

Event type whose properties match the JMS message properties.

Specify this child element only if you want Oracle CEP to automatically perform the conversion between JMS messages and events. If you have created your own custom converter bean, then do not specify this element. For more information, see Section 6.2.1, "Creating a Custom Converter Between JMS Messages and Event Types".

jndi-provider-url

Required. The URL of the JNDI provider.

jndi-factory

Optional. The JNDI factory name. Default value is weblogic.jndi.WLInitialContextFactory, for Oracle CEP server JMS.

connection-jndi-name

Optional. The JNDI name of the JMS connection factory. Default value is weblogic.jms.ConnectionFactory, for Oracle CEP server JMS.

destination-jndi-name

destination-name

Required. Either the JNDI name, or actual name, of the JMS destination. Specify one or the other, but not both.

user

Required. When Oracle CEP acquires the JNDI InitialContext, it uses the user and password (or encrypted-password) settings.

password

encrypted-password

Required. Either the password, or encrypted password, for user. Specify one or the other, but not both.

See Section 6.2.4, "Encrypting Passwords in the JMS Adapter Configuration File" for details on encrypting the password.

connection-user

Optional. When Oracle CEP calls the createConnection method on the javax.jms.ConnectionFactory to create a connection to the JMS destination (JMS queue or topic), it uses the connection-user and connection-password (or connection-encrypted-password) settings, if configured. Otherwise, Oracle CEP uses the user and password (or encrypted-password) settings.

You can use the connection-user and connection-password (or connection-encrypted-password) settings in applications where one security provider is used for JNDI access and a separate security provider is used for JMS access.

connection-password

connection-encrypted-password

Optional. Either the password, or encrypted password, for connection-user. Specify one or the other, but not both.

See Section 6.2.4, "Encrypting Passwords in the JMS Adapter Configuration File" for details on encrypting the password.

session-transacted

Boolean value that specifies whether to use transacted sessions.


Table 6-2 lists the optional child elements of jms-adapter you can configure for inbound JMS adapters only.

Table 6-2 Optional Child Elements for Inbound JMS Adapters

Child Element Description

work-manager

Name of a work manager, configured in the server's config.xml file. This name corresponds to the value of the <name> child element of the <work-manager> element in config.xml.

The default value is the work manager configured for the application itself.

concurrent-consumers

Number of consumers to create. Default value is 1.

If you set this value to number greater than one, be sure that your converter bean is thread-safe. This is because the converter bean will be shared among the consumers.

message-selector

JMS message selector to use to filter messages.

session-ack-mode-name

Session acknowledgement mode.


Table 6-3 lists the optional child elements of jms-adapter you can configure for outbound JMS adapters only.

Table 6-3 Optional Child Elements for Outbound JMS Adapters

Child Element Description

delivery-mode

Specifies the delivery mode: persistent (default value) or nonpersistent.


For the full schema for the configuration of JMS adapters, see Section B.2, "Component Configuration Schema wlevs_application_config.xsd".

The following configuration file shows a complete example of configuring both an inbound and outbound JMS adapter.

<?xml version="1.0" encoding="UTF-8"?>
<n1:config
 xsi:schemaLocation="http://www.bea.com/ns/wlevs/config/application wlevs_application_config.xsd"
 xmlns:n1="http://www.bea.com/ns/wlevs/config/application"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <jms-adapter>
        <name>jmsInbound</name>
        <jndi-provider-url>t3://localhost:7001</jndi-provider-url>
        <destination-jndi-name>Queue1</destination-jndi-name>
        <user>weblogic</user>
        <password>weblogic</password>
        <work-manager>JettyWorkManager</work-manager>
        <concurrent-consumers>1</concurrent-consumers>
        <session-transacted>false</session-transacted>
    </jms-adapter>
    <jms-adapter>
        <name>jmsOutbound</name>
        <event-type>JMSEvent</event-type>
        <jndi-provider-url>t3://localhost:7001</jndi-provider-url>
        <destination-jndi-name>Topic1</destination-jndi-name>
        <delivery-mode>nonpersistent</delivery-mode>
    </jms-adapter>
</n1:config>

The following snippet shows how to configure an inbound JMS adapter connecting to TIBCO EMS JMS:

<jms-adapter>
  <name>myJmsAdapter</name>
  <jndi-provider-url>t3://localhost:7222</jndi-provider-url>
  <jndi-factory>com.tibco.tibjms.naming.TibjmsInitialContextFactory</jndi-factory>
  <connection-jndi-name>TibcoQueueConnectionFactory</connection-jndi-name>
  <destination-jndi-name>MyQueue</destination-jndi-name>
</jms-adapter>

6.2.4 Encrypting Passwords in the JMS Adapter Configuration File

You can encrypt the password in the JMS adapter configuration file.

Note:

The procedure assumes that you are currently using the <password> element in the configuration file, along with a cleartext password value, but want to start using the <encrypted-password> element to encrypt the password.

To encrypt passwords in the JMS adapter configuration file:

  1. Open a command window and set your environment as described in "Setting Your Development Environment" in the Oracle CEP Getting Started.

  2. Change to the directory that contains the configuration file for your JMS adapter.

  3. Execute the following encryptMSAConfig command to encrypt the value of the <password> element in the configuration file:

    prompt> ORACLE_CEP_HOME/ocep_11.1/bin/encryptMSAConfig . config_file msainternal.dat_file
    

    where ORACLE_CEP_HOME refers to the main BEA directory into which you installed Oracle CEP, such as d:\oracle_cep. The second argument refers to the directory that contains the JMS adapter configuration file; because this procedure directs you to actually change to the directory, the example shows ".". The config_file parameter refers to the name of your JMS adapter configuration file. Finally, the msainternal.dat_file parameter refers to the location of the .msainternal.dat file associated with your domain; by default this file is located in the DOMAIN_DIR/servername directory, where DOMAIN_DIR refers to the domain directory such as /oracle_cep/user_projects/domains/mydomain and servername refers to the server instance.

    The encryptMSAConfig command comes in two flavors: encryptMSAConfig.cmd (Windows) and encryptMSAConfig.sh (UNIX).

    After you run the command, the value of the <password> element will be encrypted, as shown in bold in the following example:

    <jms-adapter>
      <name>jmsInbound</name>
      <jndi-provider-url>t3://localhost:7001</jndi-provider-url>
      <destination-jndi-name>Queue1</destination-jndi-name>
      <user>weblogic</user>
      <password>{Salted-3DES}B7L6nehu7dgPtJJTnTJWRA==</password>
      <work-manager>JettyWorkManager</work-manager>
      <concurrent-consumers>1</concurrent-consumers>
      <session-transacted>false</session-transacted>
    </jms-adapter>
    
  4. Using your favorite XML editor, edit the JMS adapter configuration file. Change the <password> element (whose value is now encrypted) to <encrypted-password>, as shown in bold in the following example:

    <jms-adapter>
      <name>jmsInbound</name>
      <jndi-provider-url>t3://localhost:7001</jndi-provider-url>
      <destination-jndi-name>Queue1</destination-jndi-name>
      <user>weblogic</user>
      <encrypted-password>{Salted-3DES}B7L6nehu7dgPtJJTnTJWRA==</encrypted-password>
      <work-manager>JettyWorkManager</work-manager>
      <concurrent-consumers>1</concurrent-consumers>
      <session-transacted>false</session-transacted>
    </jms-adapter>