Creating WebLogic Event Server Applications

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Using Java Message Service (JMS) in Your Applications

This section contains information on the following subjects:

 


Overview of Using JMS in WebLogic Event Server Applications

Java Message Service (JMS) can be used in a variety of places in a WebLogic Event Server appliation. In particular:

This section builds on the existing adapter and business logic POJO chapters, so be sure you read them before reading this section:

For general information about JMS, see Java Message Service on the Sun Developer Network.

 


Additional Programming Guidelines for JMS Adapters

The section Programming the Adapter Class: Guidelines describes how to generally program an adapter that reads incoming data using the APIs provided by the data feed provider. This section describes additional guidelines you should follow if your adapter reads data from a Java Message Service (JMS) object. Read the general guidelines before you read these JMS guidelines.

For the complete example of how to read JMS data in an adapter, parts of which are described in this section, see the JMS Adapter example located in the WLEVS_HOME/samples/source/adapters/jms-adapter directory, where WLEVS_HOME refers to the main WebLogic Event Server installation, such as /beahome/wlevs20.

Follow these additional guidelines when programming a JMS adapter:

 


Additional Configuration for JMS Adapters

This section describes the additional entries you must add to the EPN assembly file when implementing a JMS adapter. See Updating the EPN Assembly File for general information about configuring adapters in the EPN assembly file.

As with any adapter, you register a JMS adapter as usual using the <wlevs:adapter> tag in the EPN assembly file:

<wlevs:adapter id="inboundJmsAdapter" provider="wl-jms" manageable="true">
<wlevs:instance-property name="eventType" value="jmsEvent" />
</wlevs:adapter>

In the preceding example, provider="wl-jms" refers to an OSGI-registered adapter factory.

In addition to the standard <wlevs:adapter> tag, you must add additional entries to the EPN assembly file. In particular, you must configure:

 


Using WebLogic Event Server AsyncBeans

AsyncBeans provide a WebLogic Event Server alternative to J2EE message driven beans. It uses Spring's Message Driven POJO (MDP) support to allow a Plain Old Java Object (POJO) to act as a message listener on a JMS queue or topic.

AsyncBeans provide:

Configuring AsyncBeans using Configuration Objects

In order to use AsyncBeans declaratively, you must add appropriate tags to the EPN assembly file, located in the META-INF/spring directory of your application bundle. You can configure multiple asynchronous beans per WebLogic Event Server instance.

See the XSD Schema for the full Schema description of the <asyncbean> element you can add to the EPN assembly file.

Common AsyncBean Tasks

The following sections provide information on how to program and configure common tasks using AsyncBeans:

Asynchronous Message Reception

You can receive messages asynchronously by implementing the javax.jms.MessageListener interface.

For example:

public class MyMessageListener implements MessageListener {
    public void onMessage(Message msg) {
    System.err.println("RECEIVED: " + msg);
  }
}

Use the following tags in your EPN assembly file to connect this listener to a JMS queue:

  <bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
  <asyncbean>
<destinationName>TEST.FOO</destinationName>
<connectionFactory>connectionFactory</connectionFactory>
<messageListener>messageListener</messageListener>
</asyncbean>

Message Driven POJO

This section provides an example of a simple message-driven POJO:

public class MyPOJO {
  public void deliver(String msg) {
System.err.println("RECEIVED: " + msg);
}
}
Note: This class has no dependencies on JMS, Spring, or any other container code.

In your EPN assembly file, you must configure a MessageListenerAdapter that adapts the POJO to the javax.jms.MessageListener interface. For example:

  <bean id="messageListener"
class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
<constructor-arg><bean class="test.MyPOJO" /></constructor-arg>
<property name="defaultListenerMethod" value="deliver"/>
</bean>
  <asyncbean>
<destinationName>TEST.FOO</destinationName>
<connectionFactory>connectionFactory</connectionFactory>
<messageListener>messageListener</messageListener>
</asyncbean>

Transactions

You enable transactions setting the optional transactional property to true in your EPN assembly file:

For example:

  <asyncbean>
<destinationName>TEST.FOO</destinationName>
<transactional>true</transactional>
<connectionFactory>connectionFactory</connectionFactory>
<messageListener>messageListener</messageListener>
</asyncbean>

Retrieving JMS objects from JNDI

Use the Spring JNDI lookup mechanism to lookup ConnectionFactorys and destinations from JNDI.

For example:

  <jee:jndi-lookup id="myConnectionFactory"
jndi-name="my.connection.Factory">
    <jee:environment>
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
java.naming.provider.url=t3://localhost:10001
</jee:environment>
</jee:jndi-lookup>
  <jee:jndi-lookup id="myDestination" jndi-name="my.connection.Factory">
<jee:environment>
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
java.naming.provider.url=t3://localhost:10001
</jee:environment>
</jee:jndi-lookup>
  <asyncbean>
<destination>myDestination</destination>
<connectionFactory>myConnectionFactory</connectionFactory>
<messageListener>messageListener</messageListener>
</asyncbean>

Using WorkManager with Transactions

When using transactions, the AsyncBean framework performs a blocking receive to get messages from the underlying destination. These messages are then dispatched to the AsyncBean using a WorkManager. The following sections describe two methods to dispatch messages to an AsyncBean:

Dependency Injection Using Simple Declaritive Services

Retrieve the WorkManager from the OSGi service registry. Use this method when the WorkManager is configured in the config.xml file that describes your domain.

For example, the AsyncBean configuration object may look like:

<asyncbean>
<destinationName>TEST.FOO</destinationName>
<transactional>true</transactional>
<connectionFactory>connectionFactory</connectionFactory>
<messageListener>messageListener</messageListener>
<workManager>
<osgi:reference interface="commonj.work.WorkManager"
filter="(name=MyWorkManager"/>
</workManager>
</asyncbean>
Dependency Injection Using Spring

Use Spring to access the WorkManager.

For example, the AsyncBean configuration object may look like:

<asyncbean>
<destinationName>TEST.FOO</destinationName>
<transactional>true</transactional>
<connectionFactory>connectionFactory</connectionFactory>
| <messageListener>messageListener</messageListener>
<workManager>
<bean class="com.bea.core.workmanager.WorkManagerFactory"
factory-method="findOrCreate">
<constructor-arg value="MyWorkManager"/><!-- name parameter -->
<constructor-arg value="5"/><!-- min threads constraint -->
<constructor-arg value="10"/><!-- max threads constraint -->
</bean>
</workManager>
</asyncbean>

  Back to Top       Previous  Next