Creating a Message-Driven Bean

   

Deploying a Message-Driven Bean

Because we are not specifying the JMS objects that the message-driven bean connects to in the class itself, it must be somewhere. That somewhere is in the deployment descriptor for the bean. This is referred to as specifying the connection information declaratively . If we specified the connection information inside the source code, we would say that it's programmatic. This is another nice feature because we can change the JMS destination during deployment and not have to modify the source code.

An Example Message-Driven Bean Deployment Descriptor

To deploy your message-driven bean, you must add a message-driven element to the ejb-xml.jar file. The main things that are specified for a message-driven bean are

  • Whether the message-driven bean is for a Topic or Queue

  • If the bean is for a Topic , whether it's durable or nondurable

  • The transaction attributes for the bean

  • The acknowledge semantics to use for beans that use bean-managed transactions

Listing 11.4 shows a deployment descriptor for the message-driven bean in Listing 11.1.

Listing 11.4 AuctionNotificationMessageBean Deployment Descriptor
 <!DOCTYPE ejb-jar PUBLIC  "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"  "http://java.sun.com/dtd/ejb-jar_2_0.dtd">  <ejb-jar>   <enterprise-beans>      <message-driven>        <ejb-name>AuctionNotificationMessageBean</ejb-name>        <ejb-class>           com.que.ejb20.notification.AuctionNotificationMessageBean        </ejb-class>        <transaction-type>Container</transaction-type>        <message-driven-destination>          <jms-destination-type>javax.jms.Queue</jms-destination-type>        </message-driven-destination>        <security-identity>        <run-as>          <role-name></role-name>        </run-as>        </security-identity>      </message-driven>   </enterprise-beans>  </ejb-jar> 

Other than the name of this message-driven bean, you can also see the type of JMS destination for which this bean is a listener. It also specifies the transaction type to be container-managed transactions and not bean-managed.

Caution

In one of the earlier versions of the EJB 2.0 Specification, the ejb-name element in the deployment descriptor was listed as optional. This should be fixed in the final version. The ejb-name is required or the container might have trouble using the transaction attribute configured for the bean.


This chapter covers only the basic information for deploying a message-driven bean. For a complete discussion of the message-driven bean deployment elements within the ejb-jar.xml file, see Chapter 15, "Deployment."

Listing 11.2 shows the deployment descriptor, which is normally created by the bean provider. As part of the deployment or assembly of the rest of the application, a vendor-specific deployment descriptor must be created as well. Listing 11.5 shows an example of what the vendor-specific deployment descriptor looks like for WebLogic 6.1.

Listing 11.5 WebLogic 6.1 Deployment Descriptor for AuctionNotificationMessageBean
 <?xml version="1.0"?>  <!DOCTYPE weblogic-ejb-jar PUBLIC  "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN"  "http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd">  <weblogic-ejb-jar>    <weblogic-enterprise-bean>      <ejb-name>AuctionNotificationMessageBean</ejb-name>      <message-driven-descriptor>        <pool>          <max-beans-in-free-pool>30</max-beans-in-free-pool>          <initial-beans-in-free-pool>10</initial-beans-in-free-pool>        </pool>        <destination-jndi-name>           com.que.ejb20book.notification.Queue        </destination-jndi-name>      </message-driven-descriptor>    </weblogic-enterprise-bean>  </weblogic-ejb-jar> 

The deployment descriptor in Listing 11.5 is WebLogic-specific. However, you can get an idea of what types of things can be specified by a vendor. For example, the WebLogic deployment descriptor specifies how many instances of this message-driven bean are initially created when the container starts up, as well as the actual name of the JMS destination as specified in the JNDI naming service.



Special Edition Using Enterprise JavaBeans 2.0
Special Edition Using Enterprise JavaBeans 2.0
ISBN: 0789725673
EAN: 2147483647
Year: 2000
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net