Configuring an MDB to listen to multiple queues

你离开我真会死。 提交于 2019-11-27 06:18:50

问题


I'm using EJB 3.1 and I want to configure an MDB to listen to multiple queues.
I'd prefer defining the queue names via XML but the other definitions via annotations.
Can this be done?


回答1:


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.




回答2:


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")
    })'


来源:https://stackoverflow.com/questions/5886189/configuring-an-mdb-to-listen-to-multiple-queues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!