Message-Driven Bean Configuration
Resin 2.1

Reference Guide
EJB Reference Guide

EJBServer
JNDI
Entity Config
Relation Config
Session Config
Resin-EJB Config
SQL mapping
Transaction Config
Message Config
EJB-QL
xdoclet
Config Summary
Burlap
JMS
CORBA/IIOP
Index
Transaction Config
EJB Reference Guide
EJB-QL

Message driven beans are clients of the Java Messaging Service (JMS). Message driven beans require a JMS implementation in addition to Resin-CMP. Resin-EJB provides a simple memory-based JMS implementation.

Message driven beans are used to receive message. Sending messages uses the standard JMS API as described in Resin JMS configuration.

Message-driven beans receive messages from JMS queues and topics. The topics and queues are configured in JNDI as well as the queue-connection-factory.

<ejb-jar>
<enterprise-beans>
  <message-driven>
    <ejb-name>foo-message</ejb-name>
    <ejb-class>test.cmp_msg.TestBean</ejb-class>
    <message-driven-destination>
      <jndi-name>jms/topic</jndi-name>
    </message-driven-destination>
  </message-driven>
</enterprise-beans>
</ejb-jar>
ejb-classDefines the bean's implementation class
ejb-nameThe name of the bean
message-driven-destinationSpecifies the Queue or Topic the bean will receive messages from
message-selectorDefines a query to select only messages matching the selector

Message Bean Configuration

ejb-class

Defines the bean's implementation class.

Each message bean must specify an implementation class which implements the doMessage methods and implements both javax.ejb.MessageDrivenBean and javax.jms.MessageListener. Resin will call the bean when a new message is available.

ejb-name

The name of the bean. The value of ejb-name is used to find the bean in JNDI.

message-driven-destination

Specifies the Queue or Topic the bean will receive messages from.

message-driven-destination attributes
AttributeMeaning
destination-typeeither javax.jms.Queue or javax.jms.Topic
jndi-nameJNDI name of the queue or topic for the bean.
subscription-durabilityFor topics, 'Durable' means the topic is durable across server restarts.
durable-subscription-nameThe subscription name of a durable topic.

message-selector

Defines a query to select only messages matching the selector.

Third-Party Products

SwiftMQ

The SwiftMQ client is configured by adding a jndi-link to the web.xml or resin.conf.

Resin needs the swiftmq.jar from the SwiftMQ distribution in the classpath, either in resin/lib/swiftmq.jar or in WEB-INF/lib.

web.xml
<web-app>
  <jndi-link>
    <jndi-name>java:comp/env/jms</jndi-name>
    <jndi-factory>com.swiftmq.jndi.InitialContextFactoryImpl</jndi-factory>
    <init-param java.naming.provider.url="smqp://localhost:4001/timeout=10000"/>
  </jndi-link>

  <resource-ref>
    <res-ref-name>java:comp/env/cmp</res-ref-name>
    <class-name>com.caucho.ejb.EJBServer</class-name>
    <init-param queue-connection-factory="java:comp/env/jms/QueueConnectionFactory"/>
  </resource-ref>
</web-app>

The msg.ejb will contain the queue's name:

msg.ejb
<ejb-jar>
<enterprise-beans>
  <message-driven>
    <ejb-name>foo</ejb-name>
    <ejb-class>test.MyMessageBean</ejb-class>
    <message-driven-destination>
      <jndi-name>jms/testqueue@router1</jndi-name>
    </message-driven-destination>
  </message-driven>
</enterprise-beans>
</ejb-jar>

The SwiftMQ router will need to be started as a separate process.


Transaction Config
EJB Reference Guide
EJB-QL
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.