【问题标题】:Configuring an MDB to listen to multiple queues配置 MDB 以侦听多个队列
【发布时间】:2011-08-18 16:12:52
【问题描述】:

我正在使用 EJB 3.1,我想配置一个 MDB 来监听多个队列。
我更喜欢通过 XML 定义队列名称,但通过注释定义其他定义。
这个可以吗?

【问题讨论】:

    标签: java jms message-driven-bean


    【解决方案1】:

    使用 ejb-jar.xml 代替 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>
    

    并从您的 Java 类中删除 @MessageDriven 注释

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

    【讨论】:

      【解决方案2】:

      一旦实例化,MDB 只能侦听在其目标 ActivationConfigProperty 中指定的资源,但是您可以创建具有不同目标(在您的情况下为队列)的同一 MDB 的多个实例。 p>

      在您的 ejb-jar.xml 中创建两个具有不同目标和 ejb-name 属性但相同 ejb-class 的条目。

      【讨论】:

      • 您好 jperdham,感谢您的回答。你的意思是我应该通过 ActivationConfigProperty 注释定义我想要的所有属性,并且在 ejb-jar.xml 中以不同方式定义目标和 ejb-name?
      • 嘿 Ittai,您可以将 ActivationConfigProperty 放在 ejb-jar.xml 或注释中,这完全取决于您将属性放在哪里。如果您有一组属性要进行大量更改或逐台更改,那么在 xml 中更改它们比创建应用程序的新版本更容易。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-07
      • 2013-09-24
      • 2018-04-08
      • 2016-12-31
      • 1970-01-01
      • 2016-06-14
      相关资源
      最近更新 更多