Oracle® Application Server Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 2 (10.1.2) Part No. B15505-01 |
|
![]() Previous |
![]() Next |
A Message-Driven Bean (MDB) is a Java Message Service (JMS) message listener that can reliably consume messages from a queue or a topic. An MDB uses the asynchronous nature of a JMS listener with the benefit of the EJB container, which does the following:
The EJB container creates a consumer of type QueueReceiver
or TopicSubscriber
for the listener.
At deployment time, the EJB container registers the MDB with the consumer, which is either a QueueReceiver
or TopicSubscriber
, and its factory.
The EJB container specifies the message acknowledgment mode.
Within normal JMS objects, a JMS message listener exists and must explicitly specify the consumer and its factory within its code. When you use MDBs, the container specifies the consumer and its factory for you; thus, an MDB is an easy method for creating a JMS message listener. You still have to retrieve the objects and create them given the interface, but the container does most of the work for you.
The OC4J MDB interacts with a JMS provider. This chapter highlights two JMS providers, OracleAS JMS and Oracle JMS, each of which must be installed and configured appropriately.
OracleAS JMS is installed internally within the OC4J code base.
Oracle JMS (Advanced Queuing) is installed and configured within an Oracle database. Before using Oracle JMS, you must create the appropriate queue or table in the database.
Note: A full description of how to use each JMS provider is discussed in the JMS chapter in the Oracle Application Server Containers for J2EE Services Guide. In addition, for information on security, see the Oracle Application Server Containers for J2EE Security Guide. |
The following are generic steps to create and enable an MDB with a JMS provider:
Install the JMS provider.
Configure the JMS provider, the Destination
objects for the MDB, and connection details for the MDB where the provider is installed.
Configure OC4J with the JMS provider details in the OC4J XML files.
Implement the MDB and map the JMS Destination
objects used in its deployment descriptors.
This chapter describes how to implement each of these steps with both the OracleAS JMS and Oracle JMS providers. Each section uses an MDB example that is available for download from the OC4J sample code page at on the OTN Web site.
The main MDB implementation and the EJB deployment descriptor can be the same for both JMS types and is shown in the "MDB Example". The OC4J-specific deployment descriptor for this MDB and the JMS configuration is different for each JMS type, so these are described specifically in each of the provider sections.