Getting Started with Enterprise JavaBeans™

G

Message-Driven Beans

Tutorial Home Section Home Previous Section Next

Get

Get

Using Message-Driven Beans

     After going through the JMS information, you'll probably find it surprisingly simple to code message-driven beans. That's because the container handles all of the steps mentioned in The Java Message Service except actually receiving the messages. In general, the same MDB can be used to receive PTP or pub/sub messages by setting the appropriate ConnectionFactory, destination, and destination type on deployment. As is often the case with EJB technology, some of this coding ease translates into more complexity in the deployment descriptor.

     An MDB must have a public, no-arg constructor, and is not allowed to throw application exceptions. In addition, an MDB must implement the following methods (for the life cycle sequence, see Message-Driven Beans Overview):

     Once the message has been received, the MDB can perform all the operations itself, or act as a manager, sending the information to and controlling other beans. Queue architecture is fairly limited, because the specification envisions a queue for each bean type. It also warns against deploying multiple beans against the same queue, primarily citing message order concerns; however, there is no guaranteed order for message receipt in any event. The deployment descriptor does allow for JMS message selectors to direct specific messages to a specific bean type.



Tutorial Home Section Home Previous Section Next