消息驱动的 bean 部署描述符示例

下列代码示例说明了用来定义消息驱动的 bean 的 EJB 2.0 和 EJB 2.1 部署描述符元素之间的差异。

EJB 2.0

此代码样本显示了部署描述符中有关 EJB 2.0 消息驱动的 bean 的描述:

<message-driven id="Mdb20">
  <ejb-name>Mdb</ejb-name>
  <ejb-class>ejbs.MdbBean</ejb-class>
  <transaction-type>Bean</transaction-type>
  <message-selector>mdbMessage</message-selector>
  <acknowledge-mode>Auto-acknowledge</acknowledge-mode>
  <message-driven-destination>
    <destination-type>javax.jms.Topic</destination-type>
    <subscription-durability>Durable</subscription-durability>
  </message-driven-destination>
</message-driven>

EJB 2.1

此代码样本显示了部署描述符中有关 EJB 2.1 消息驱动的 bean 的描述:

<message-driven id="Mdb21">
  <ejb-name>Foo</ejb-name>
  <ejb-class>ejbs.FooBean</ejb-class>
  <messaging-type>javax.jms.MessageListener</messaging-type>
  <transaction-type>Bean/transaction-type>
  <message-destination-type>javax.jms.Topic</message-destination-type>
  <activation-config>
    <activation-config-property>
      <activation-config-property-name>destinationType</activation-config-property-name>
      <activation-config-property-value>javax.jms.Topic</activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
      <activation-config-property-name>subscriptionDurability</activation-config-property-name>
      <activation-config-property-value>Durable</activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
      <activation-config-property-name>acknowledgeMode</activation-config-property-name>
      <activation-config-property-value>AutoAcknowledge</activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
      <activation-config-property-name>messageSelector</activation-config-property-name>
      <activation-config-property-value>fooSelector</activation-config-property-value>
    </activation-config-property>
  </activation-config>
  </transaction-type>
</ejb-name>
</message-driven>

在 EJB 2.1 中,规范定义了 <activation-config-property> 元素,它可用来定义应答方式、消息选择器、预订持久性和目标类型等属性。使用非 JMS 消息传递类型时,向导允许定义需要用于 bean 的 <activation-config-property> 名称和值对。对于 JMS 消息传递系统,向导提供了 JMS 所需的缺省配置属性,例如预订持久性应答方式


反馈