Table of Contents
This chapter describes some precautions for using Message Driven Beans (MDBs) in the JEUS engine.
The EJB engine concurrently executes multiple message driven bean instances. It can also process message streams. Since the EJB engine cannot guarantee the accuracy of the order in which messages arrive in the message driven bean class, it does not transmit the messages in the order they are received. Instead, it randomly selects a message to transmit.
MDB also does not guarantee the order of processing the requests. For example, since a message to cancel a reservation may arrive before the message to make a reservation, message processing order should be considered when designing the MDB.
Concurrency is processed when the bean pool obtains an Instance from MDB and delegate it to the request.. This is identical to the behavior of the Thread Ticket Pool (TTP) of stateless session beans. For MDB, a <pool-max> setting, instead of the <thread-max> setting, should be used. For more information, refer to "Chapter 7. Session Beans".
Some MDB-specific configurations are required in order for the EJB engine to execute MDB beans. Other than the MDB-specific configurations, MDBs share some basic EJB settings with other JEUS bean types.
This section will very briefly discuss:
The basic settings of MDB in the JEUS EJB DD (a sub-set of the settings described in "Chapter 4. Common Characteristics of EJB").
The JMS-specific settings of JEUS MDB that are configured in the JEUS EJB DD file.
These configurations should be self-explanatory for anyone familiar with MDB.
MDB shares a few similar basic settings with the other EJB types. The settings you can set up for each MDB are <ejb-name>, <run-as identity>, and <security-interop> elements.
The following is an example of configuring basic MDB settings.
[Example 9.1] Configuring Basic Settings: <<jeus-ejb-dd.xml>>
<jeus-ejb-dd> . . . <beanlist> . . . <jeus-bean> <ejb-name>order</ejb-name> <!--JMS settings goes here (see "9.2.2. Configuring JMS Settings" )--> <run-as-identity> . . . </run-as-identity> <security-interop> . . . </security-interop> <env> . . . </env> <ejb-ref> . . . </ejb-ref> <res-ref> . . . </res-ref> <res-env-ref> . . . </res-env-ref> <!-- No clustering of MDB --> </jeus-bean> . . . </beanlist> . . . </jeus-ejb-dd>
Different settings are required for different message types processed by MDB. The JMS connection factory export name is required to process JMS messages, and the resource adaptor is required to process connector messages.
The following is a section of the XML document that shows annotation settings of a MDB class .
[Example 9.2] Configuring JMS Settings: <<MyMDB.class>>
@MessageDriven( activationConfig = { @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"), @ActivationConfigProperty(propertyName="acknowlegeMode", propertyValue="Auto-acknowledge") }, mappedName = "jms/QUEUE1" ) public class MyMDB implements MessageListener { ... }
[Example 9.3] Configuring JMS Settings: <<jeus-ejb-dd.xml>>
<jeus-ejb-dd> . . . <beanlist> . . . <jeus-bean> . . . <ejb-name>MyMDB</ejb-name> <connection-factory-name> QueueConnectionFactory </connection-factory-name> <destination>jms/QUEUE1</destination> <max-message>15</max-message> <activation-config> <activation-config-property> <activation-config-property-name> destinationType </activation-config-property-name> <activation-config-property-value> javax.jms.Queue </activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name> acknowlegeMode </activation-config-property-name> <activation-config-property-value> Auto-acknowledge </activation-config-property-value> </activation-config-property> </activation-config> . . . </jeus-bean> . . . </beanlist> . . . </jeus-ejb-dd>
Descriptions for each element are as follows:
A JNDI export name of the JMS connection factory.
This setting can be configured from several locations as shown in the following example, and their priorities are as follows:
jeus-ejb-dd.xml/<jeus-bean>/<connection-factory-name>
jeus-ejb-dd.xml/<jeus-bean>/<activation-config> property name: jeus.connectionFactoryName
@ActivationConfigProperty property name: jeus.connectionFactoryName
A resource adaptor that is used to connect to the Messaging System through JEUS connector. Use the module id specified in jeus-connector-dd.xml of the resource adapter.
A JNDI name of JMS Destination.
This setting can be configured from several locations as shown in the following example, and their priorities are as follows:
jeus-ejb-dd.xml/<jeus-bean>/<destination>
<message-driven>/<mapped-name> of ejb-jar.xml
mappedName of @MessageDriven
<message-driven>/<message-destination-link> of ejb-jar.xml
Used by MDB when using a JMS service which is registered to a JNDI naming service other than the default one (jeus.jndi.JNSContextFactory). That is, it is used when connecting JEUS MDB to a service, such as IBM MQ or SONIC MQ, other than JEUS JMS service.
Used to specify the maximum number of messages that can be assigned to each session for registering and processing multiple JMS session.
If the number of messages in a queue is smaller than the specified number, one session continues to process the requests. If the number is larger than the specified number, another session is used. When the specified number is 10, one session processes the messages until the number of messages exceeds 10. This helps reduce the load. For details, refer to the JMS specification.
Used to override activation config of ejb-jar.xml with the activation config which will be used for JMS or resource adapter.
For JMS MDB, acknowledgeMode, messageSelector, destinationType, and subscriptionDurability properties are recognized by default. You may additionally use the previously mentioned properties, jeus.connectionFactoryName, jeus.clientId, and jeus.subscriptionName. The jeus.clientId and jeus.subscriptionName properties are provided for DurableSubscription of the Topic. If they are not specified, the "Module Name"/"Bean Name" are used for them, respectively.
These settings can be configured from several locations as shown in the following example, and their priorities are as follows:
jeus-ejb-dd.xml의 <activation-config>
ejb-jar.xml의 <activation-config>
@ActivationConfig
Specifies the acknowledge mode of the JMS session.
These settings can be configured from several locations as shown in the following example, and their priorities are as follows:
jeus-ejb-dd.xml/<jeus-bean>/<ack-mode>
jeus-ejb-dd.xml/<jeus-bean>/<activation-config> property name: acknowlegeMode
ejb-jar.xml/<message-driven-bean>/<activation-config> property name: acknowlegeMode
ejb-jar.xml/<message-driven-bean>/<acknowledge-mode>
@ActivationConfigProperty property name: acknowledgeMode
Specifies durable subscriber of JMS.
These settings can be configured from several locations as shown in the following example, and their priorities are as follows:
jeus-ejb-dd.xml/<jeus-bean>/<durable>
jeus-ejb-dd.xml/<jeus-bean>/<activation-config> property name: subscriptionDurablity
ejb-jar.xml/<message-driven-bean>/<activation-config> property name: subscriptionDurablity
ejb-jar.xml/<message-driven-bean>/<subscription-durability>
@ActivationConfigProperty property name: subscriptionDurablity
Specifies the JMS message selector.
These settings can be configured from several locations as shown in the following example, and their priorities are as follows:
jeus-ejb-dd.xml/<jeus-bean>/<msg-selector>
jeus-ejb-dd.xml/<jeus-bean>/<activation-config> property name: messageSelector
ejb-jar.xml/<message-driven-bean>/<activation-config> property name: messageSelector
ejb-jar.xml/<message-driven-bean>/<message-selector>
@ActivationConfigProperty property name: messageSelector
For information about the previous settings, refer to one of: "JEUS MQ Guide", "JEUS JCA Guide", "JMS standard", and "EJB standard".
JEUS MDB basically uses JMS connections by looking them up with a JEUS Naming Service.
If you are using another JMS service (IBM MQ or SONIC MQ), connections may be obtained through the service. In this case, the MDB using an external naming service, including a JMS service, may be configured. You may add a <jndi-spi> element for each MDB that requires it to look up a JMS service.
The following is an example of configuring JNDI SPI.
[Example 9.4] Configuring JNDI SPI: <<jeus-ejb-dd.xml>>
<jeus-ejb-dd> . . . <beanlist> . . . <jeus-bean> . . . <jndi-spi> <mq-vendor>SONICMQ</mq-vendor> <initial-context-factory> acme.jndi.ACMEContextFactory </initial-context-factory> <provider-url> protocol://localhost:2345 </provider-url> </jndi-spi> . . . </jeus-bean> . . . </beanlist> . . . </jeus-ejb-dd>
Descriptions for each element are as follows: