开发者

With EJB 2.1, is declaring references to resources in ejb-jar.xml required?

I'm using Weblogic 9.2 with a lot of MDBs. These MDBs access JDBC DataSources and write to both locally and externally managed JMS Des开发者_StackOverflow中文版tinations using local and foreign XAConnectionFactorys, respectively. Each MDB demarcates a container-managed JTA transaction that should be distributed amongst all of these resources.

Below is an excerpt from my ejb-jar.xml for an MDB that consumes from a local Queue called "MyDestination" and produces to an IBM Websphere MQ Queue called "MyOtherDestination". These logical names are linked to physical objects in my weblogic-ejb-jar.xml file.

Is it required to use the <resource-ref> and <message-destination-ref> tags to expose the ConnectionFactory and Queue to the MDB? If so, is it required by Weblogic or is it required by the J2EE spec? And for what purpose? For example, is it required to support XA transactionality?

I'm already aware of the benefit of decoupling the administered objects from my MDB using names exposed to the naming context of the MDB. Is this the only value added when specifying these tags? In other words, is it acceptable to just reference these objects from my MDB using the InitialContext and the objects' fully-qualified names?

<enterprise-bean>
    <message-driven>
        <ejb-name>MyMDB</ejb-name>
        <ejb-class>com.mycompany.MyMessageDrivenBean</ejb-class>
        <transaction-type>Container</transaction-type>
        <message-destination-type>javax.jms.Queue</message-destination>
        <message-destination-link>MyDestination</message-destination-link>
        <resource-ref>
            <res-ref-name>jms/myQCF</res-ref-name>
            <res-type>javax.jms.XAConnectionFactory</res-type>
            <res-auth>Container</res-auth>
        </resource-ref>
        <message-destination-ref>
            <message-destination-ref-name>jms/myOtherDestination</message-destination-ref-name>
            <message-destination-type>javax.jms.Queue</message-destination-type>
            <message-destination-usage>Produces</message-destination-usage>
            <message-destination-link>MyOtherDestination</message-destination-link>
        </message-destination-ref>
    </message-driven>
<enterprise-bean>


I poured over Weblogic/J2EE documentation for a day, posted the above question, then as expected I immediately came across the documentation I was looking for.

At a minimum I need to declare a <resource-ref> for the remote ConnectionFactory (in my case, IBM Websphere MQ) in order to enlist its connections in the JTA transaction.

The corresponding <message-destination-ref> for the remote Destination is added for consistency and there is no real value-add here from the Weblogic perspective. In addition there is no value-add when specifying references to locally administered Destinations, ConnectionFactorys, and Datasources.

From Weblogic's FAQs: Integrating Remote JMS Providers:

Q. What advantages do JMS resource references provide?

A. JMS resource references provide the following advantages:

  • They ensure portability of servlet and EJB applications: they can be used to change an application's JMS resource without recompiling the application's source code.
  • They provide automatic pooling of JMS Connection, Session, and MessageProducer objects.
  • They provide automatic transaction enlistment for non-WebLogic JMS providers. This requires XA support in the JMS provider. If resource references aren't used, then enlisting a non-WebLogic JMS provider with the current transaction requires extra programmatic steps.

The details of this functionality are described at Enhanced J2EE Support for Using WebLogic JMS With EJBs and Servlets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜