Configuring an MDB to listen to multiple queues

前端 未结 2 1282
傲寒
傲寒 2020-12-11 08:42

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.

相关标签:
2条回答
  • 2020-12-11 08:43

    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")
        })'
    
    0 讨论(0)
  • 2020-12-11 09:03

    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.

    0 讨论(0)
提交回复
热议问题