Special Edition Using Enterprise JavaBeans 2.0

   

Using JMS Queues or Topics with Message-Driven Beans

You can use a message-driven bean to asynchronously receive messages from a javax.jms.Queue or a javax.jms.Topic . When a message-driven bean is acting as a subscriber to a Topic , it can be set up as either a non-durable or durable subscriber. In most production applications, you'll typically want to use either a persistent Queue or ensure that the message-driven bean is a durable subscriber. This will help ensure that messages are not missed.

The bean provider might provide information to the deployer as to whether the bean should be used with a Queue or a Topic by setting the message-driven-destination tag in the ejb-jar.xml file. The following code fragment shows an example of a message-driven bean being associated with a Topic :

<message-driven> <ejb-name>MessageDrivenBeanExample</ejb-name> <ejb-class>com.que.ejb20.SomeMessageBean</ejb-class> <transaction-type>Container</transaction-type> <message-driven-destination> <jms-destination-type>javax.jms.Topic</jms-destination-type> </message-driven-destination> </message-driven>

Notice that in the jms-destination-type element, a javax.jms.Topic was specified. To indicate that the message-driven bean should be used with a Queue , you would insert javax.jms.Queue instead.

We'll talk about the other elements in the deployment descriptor for a message-driven bean later in this chapter in the section, "Deploying a Message-Driven Bean."

Категории