Configure MDB to listen to multiple queues

I am using EJB 3.1 and I want to configure MDB to listen to multiple queues.
I would prefer to define queue names through XML, but other definitions through annotations.
It can be done?

+3
source share
2 answers

After creating an instance, the MDB can only listen on the resource specified in their destination ActivationConfigProperty, however you can create several instances of the same MDB with different addresses (queues in your case).

Create two entries in your ejb-jar.xml with different destination properties and ejb-name, but with the same ejb class.

+6
source

use ejb-jar.xml instead of ibm-ejb-jar-bnd.xml

    <message-driven>
        <ejb-name>MessageDrivenBean1</ejb-name>
        <ejb-class>com.sample.MessageDrivenBean</ejb-class>
        <messaging-type>javax.jms.MessageListener</messaging-type>
        <transaction-type>Container</transaction-type>
        <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>
    </message-driven>

    <message-driven>
        <ejb-name>MessageDrivenBean2</ejb-name>
        <ejb-class>com.sample.MessageDrivenBean</ejb-class>
        <messaging-type>javax.jms.MessageListener</messaging-type>
        <transaction-type>Container</transaction-type>
        <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>
    </message-driven>

</enterprise-beans>

@MessageDriven Java

'@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
    })'
0

All Articles