- Characteristics of MDBs
- Elements of MDBs
- The Life Cycle of MDBs
- Comparing MDBs with Session and Entity Beans
- Rules for Writing the MDB Class and Its Methods
- MDB EJB Sample Application: RosterMDB
- RosterApp Deployment Descriptors
- Summary
Comparing MDBs with Session and Entity Beans
Let's compare and contrast message-driven beans with session and entity beans. Unlike the session and entity beans, MDBs use asynchronous communication, and there are other differences as well:
MDBs interact using lightweight JMS messages, making them fast and reliable because they consume fewer resources than the session and entity beans that depend on heavyweight RMI-IIOP and synchronous communication.
The message sender and receiver don't have to be available simultaneously. If the target message receiver is down, the message is stored and forwarded later when the target server comes up. With session and entity beans, the client cannot invoke the business logic if the server is down.
MDBs support loosely coupled one-to-one and one-to-many delivery of messages, thus providing a more flexible solution for distributed communication. Session and entity beans are restricted to one-to-one interactiononly one client can make an RMI-IIOP invocation to one component at a time.
Due to the asynchronous nature of MDBs, the client cannot propagate the transaction and security contexts to the MDB instance and thus cannot control the transaction and security behaviors of the MDB instances. This is in contrast to session and entity beans, where the client can indeed propagate and control the transaction and security contexts. Please refer to the matrix in Table 13-1 that compares various aspects of MDBs with session and entity beans.
An MDB developer is responsible for
- defining a JMS message type
- creating a deployment descriptor file
- providing optional helper classes
Table 13-1 Comparing Message-Driven Beans with Session and Entity Beans
Feature |
MDB |
SLSB |
SFSB |
BMP |
CMP |
State type |
Stateless |
Stateless |
Stateful |
N/A |
N/A |
Instance pooling |
Yes |
Yes |
No |
Yes |
Yes |
Transaction |
Transaction aware |
Transaction aware |
Transaction aware |
Transactional |
Transactional |
Local and remote interfaces |
No |
Yes |
Yes |
Yes |
Yes |
Type of communication |
Aynchronous |
Synchronous |
Synchronous |
Synchronous |
Synchronous |
Communication method |
JMS messages |
RMI-IIOP |
RMI-IIOP |
RMI-IIOP |
RMI-IIOP |
Business method |
onMessage() |
zero or more |
zero or more |
zero or more |
zero or more |