「エンタープライズ Bean の作成」ウィザードを使用して、EJB 2.0 または EJB 2.1 メッセージ駆動型 Bean を作成できます。
メッセージ駆動型 Bean は、Java Message Service (JMS) からの非同期メッセージの処理をサポートするために EJB 2.0 で導入されました。 EJB 2.1 仕様は、メッセージ駆動型 Bean が JMS だけではなくあらゆるメッセージング・システムをサポートできるように、メッセージ駆動型 Bean の定義を拡張します。それに応じて、メッセージ駆動型 Bean の定義に使用されるデプロイメント記述子エレメントは EJB 2.1 仕様で変更されました。EJB 2.1 メッセージ駆動型 Bean 作成のためのウィザードにも、オプションで非 JMS メッセージング・システムとその活動化構成エレメントを定義するための追加ページが組み込まれています。
以下のコード・サンプルは、メッセージ駆動型 Bean の定義に用いられる EJB 2.0 および EJB 2.1 デプロイメント記述子エレメント間の違いを示しています。
<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>
<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 が必要とするデフォルト構成プロパティー (subscriptionDurability や acknowledgeMode など) が提供されます。
EJB 2.0 または EJB 2.1 メッセージ駆動型 Bean の作成手順は次のとおりです。