Chapter 9. Message Driven Beans (MDBs)

Table of Contents

9.1. Overview
9.2. Configuring MDBs
9.2.1. Configuring Basic Settings
9.2.2. Configuring JMS Settings
9.2.3. Configuring JNDI SPI

This chapter describes some precautions for using Message Driven Beans (MDBs) in the JEUS engine.

9.1. Overview

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".

9.2. Configuring MDBs

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:

Note

These configurations should be self-explanatory for anyone familiar with MDB.

9.2.1. Configuring Basic Settings

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> 
 


9.2.2. Configuring JMS Settings

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:

  • <connection-factory-name>

    • 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:

      1. jeus-ejb-dd.xml/<jeus-bean>/<connection-factory-name>

      2. jeus-ejb-dd.xml/<jeus-bean>/<activation-config> property name: jeus.connectionFactoryName

      3. @ActivationConfigProperty property name: jeus.connectionFactoryName

  • <mdb-resource-adapter>

    • 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.

  • <destination>

    • 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:

      1. jeus-ejb-dd.xml/<jeus-bean>/<destination>

      2. <message-driven>/<mapped-name> of ejb-jar.xml

      3. mappedName of @MessageDriven

      4. <message-driven>/<message-destination-link> of ejb-jar.xml

  • <jndi-spi>

    • 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.

  • <max-messages>

    • 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.

  • <activation-config>

    • 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:

      1. jeus-ejb-dd.xml의 <activation-config>

      2. ejb-jar.xml의 <activation-config>

      3. @ActivationConfig

  • <ack-mode>

    • 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:

      1. jeus-ejb-dd.xml/<jeus-bean>/<ack-mode>

      2. jeus-ejb-dd.xml/<jeus-bean>/<activation-config> property name: acknowlegeMode

      3. ejb-jar.xml/<message-driven-bean>/<activation-config> property name: acknowlegeMode

      4. ejb-jar.xml/<message-driven-bean>/<acknowledge-mode>

      5. @ActivationConfigProperty property name: acknowledgeMode

  • <durable>

    • 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:

      1. jeus-ejb-dd.xml/<jeus-bean>/<durable>

      2. jeus-ejb-dd.xml/<jeus-bean>/<activation-config> property name: subscriptionDurablity

      3. ejb-jar.xml/<message-driven-bean>/<activation-config> property name: subscriptionDurablity

      4. ejb-jar.xml/<message-driven-bean>/<subscription-durability>

      5. @ActivationConfigProperty property name: subscriptionDurablity

  • <msg-selector>

    • 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:

      1. jeus-ejb-dd.xml/<jeus-bean>/<msg-selector>

      2. jeus-ejb-dd.xml/<jeus-bean>/<activation-config> property name: messageSelector

      3. ejb-jar.xml/<message-driven-bean>/<activation-config> property name: messageSelector

      4. ejb-jar.xml/<message-driven-bean>/<message-selector>

      5. @ActivationConfigProperty property name: messageSelector

Note

For information about the previous settings, refer to one of: "JEUS MQ Guide", "JEUS JCA Guide", "JMS standard", and "EJB standard".

9.2.3. Configuring JNDI SPI

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:

ElementDescription
<mq-vendor>Name of the MQ/JMS vendor from which the MDB will obtain a connection (through the JNDI Naming Service configured in this element). Legal values are "IBMMQ" and "SONICMQ".
<initial-context-factory>Class name of the JNDI InitialContext Factory for the naming server is used to connect with the JMS service.
<provider-url>URL used to connect to the naming service.