Java Reference
In-Depth Information
Simplified messaging code
MDBs relieve you from coding the mechanical aspects of processing JMS messages—tasks
like retrieving connection factories or destinations, creating connections, opening sessions,
creating consumers, and attaching listeners. As you'll see when you build the Turtle
message-consumer MDB, all these tasks are handled behind the scenes for you. In EJB 3,
using sensible defaults for common circumstances eliminates most of the configuration. In
the worst-case scenario, you'll have to supply configuration information using simple an-
notations or through the deployment descriptor.
Robust message processing
As we mentioned earlier, reliability is a critical hallmark of MDBs. All MDBs use trans-
actions and message acknowledgment by default. What this means is that messages aren't
removed from the message server unless an MDB message listener method completes nor-
mally. If an unexpected error occurs during message processing, the transaction is marked
for rollback and the message receipt isn't acknowledged. Because MDBs use JTA transac-
tions, any database changes made during message listener processing are also automatic-
ally rolled back. As a result, the unacknowledged message can be reprocessed by the MDB
cleanly without your having to do any work. In case of successful message processing,
database changes are committed and the message is removed from the message server in
an atomic fashion.
Starting message consumption
To start picking up messages from the shipping request queue, someone needs to invoke
the appropriate method in your code. In a production environment, it's not clear how this
will be accomplished. Starting message consumption through a user-driven manual process
obviously isn't desirable. In a server environment, almost every means of executing the
method on server startup is highly system-dependent, not to mention awkward. The same
is true about stopping message processing manually. On the other hand, registered MDBs
would be bootstrapped or torn down gracefully by the container when the server is started
or stopped.
We'll continue exploring these points shortly as we start investigating a real example of
developing MDBs.
Search WWH ::




Custom Search