J2EE Messaging
909
Message-Driven Bean Deployment
The following deployment descriptor will deploy MyMessageBean. Save it as ejb-jar.xml:
<!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>myMessageBean</ejb-name>
<ejb-class>mailbean.MyMessageBean</ejb-class>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<jms-destination-type>javax.jms.Topic</jms-destination-type>
</message-driven-destination>
<security-identity>
<run-as-specified-identity>
<role-name>foo</role-name>
</run-as-specified-identity>
</security-identity>
</message-driven>
</enterprise-beans>
</ejb-jar>
The deployment descriptor must contain the <message-driven> deployment descriptor element
within the <enterprise-beans> element.
The deployment descriptor must also contain the following elements:
q
The <ejb-name> is the same as the equivalent element in a session or entity bean
deployment descriptor.
q
The <ejb-class> is the same as the equivalent element in a session or entity bean
deployment descriptor.
q
The <transaction-type> is the same as the equivalent element in a session or entity bean
deployment descriptor. Note that it specifies the database transaction context of the message
bean; this is not the same as the message transactions discussed in the "Transactions"
section of this chapter. Also note that the message-driven bean never receives a transaction
context from the client that sends the message. The bean developer always specifies the bean's
transaction context in the deployment descriptor and the onMessage() method will
always be called with this transaction context. If the bean uses container-managed transactions
its transaction attribute must be specified as either Required or NotSupported; again this is
because no client transaction is provided.
q
The <security-identity> is the same as the equivalent element in a session or entity bean
deployment descriptor. Note, though, that the identity must be <run-as-specified-
identity>, because the message bean receives no security context from the client who sent
the message.
q
The <message-driven-destination> specifies a single queue or topic for the bean to
listen on. If the developer specifies a topic they may also define whether or not the topic
subscription is durable with the <jms-subscription-durability> element.
The container handles message acknowledgement. You should not use JMS APIs for message
acknowledgement.