Java Reference
In-Depth Information
EE container, you can use the message inflow contract to have an asynchronous message
delivered to an endpoint inside the container. A JCA endpoint is essentially the same as
a JMS destination—it acts as a server proxy to an MDB (a message consumer/listener in
JMS terms). As soon as a message arrives at the end point, the container triggers any re-
gistered MDBs listening to the endpoint and delivers the message to it.
For its part, the MDB implements a listener interface that's appropriate to the JCA con-
nector/message type, passes activation configuration parameters to the JCA connector, and
registers as a listener to the JCA connector (we'll discuss message listeners and activation
configuration parameters shortly). JCA also enables MOM providers to integrate with Java
EE containers in a standardized manager using a JCA-compliant connector or resource ad-
apter. For more information, visit the JCA JSR for Java EE 7 at http://jcp.org/en/jsr/de-
tail?id=322 .
4.3.1. When to use messaging and MDBs
Messaging and MDBs are powerful concepts, but they're not right for every use case. As
a rule of thumb, you should use MDBs only if you require asynchronous processing, loose
coupling, and reliability—that is, unless you need all three of these characteristics, you
probably don't need MDB.
If you simply need asynchronous processing and not reliability or loose coupling, you
should opt to use the session bean @Asynchronous annotation described in chapter 3 .
The @Asynchronous annotation is obviously not loosely coupled because you invoke
the asynchronous session bean method directly from the client code. It's less obvious that
session bean asynchronous methods are also not reliable. If the container crashes in the
middle of asynchronous processing, the session bean is lost. With MDBs, on the other
hand, the JMS message isn't removed from the middleware until the MDB finishes pro-
cessing the message. If the MDB suddenly crashes before finishing processing, the mes-
sage is reprocessed later when the container is ready again.
Similarly, if all you need is loose coupling, you should take a close look at CDI events.
As we'll discuss in chapter 12 , CDI events allow message consumers and producers to be
separated through elegant type-safe object-based events. Like session bean asynchronous
Search WWH ::




Custom Search