【发布时间】:2011-08-18 16:12:52
【问题描述】:
我正在使用 EJB 3.1,我想配置一个 MDB 来监听多个队列。
我更喜欢通过 XML 定义队列名称,但通过注释定义其他定义。
这个可以吗?
【问题讨论】:
标签: java jms message-driven-bean
我正在使用 EJB 3.1,我想配置一个 MDB 来监听多个队列。
我更喜欢通过 XML 定义队列名称,但通过注释定义其他定义。
这个可以吗?
【问题讨论】:
标签: java jms message-driven-bean
使用 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>
'@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})'
【讨论】:
一旦实例化,MDB 只能侦听在其目标 ActivationConfigProperty 中指定的资源,但是您可以创建具有不同目标(在您的情况下为队列)的同一 MDB 的多个实例。 p>
在您的 ejb-jar.xml 中创建两个具有不同目标和 ejb-name 属性但相同 ejb-class 的条目。
【讨论】: