Configuring an MDB to listen to multiple queues

折月煮酒 提交于 2019-11-28 11:39:17

Once instantiated, an MDB can only listen to the resource specified in their destination ActivationConfigProperty, however you can create multiple instances of the same MDB with different destinations (queues, in your case).

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

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>

And remove @MessageDriven annotation from your Java class

'@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
    })'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!