Java Reference
In-Depth Information
The @MessageDriven annotation identifies this object as an MDB and specifies
the MDB configuration, including the fact that you're listening on the jms/Ship-
pingRequestQueue . Recall from the “ JCA connectors and messaging ” sidebar that
MDBs may be configured to listen for notifications other than JMS messages on queues
and topics. But in this example, Turtle's MDB implements the MessageListener in-
terface, marking it a JMS MessageListener interface . To implement the Mes-
sageListener interface, code is given for the onMessage method . The body of
this method is simple. First, the ActionBazaarShippingRequest is retrieved from
the ObjectMessage . Recall that the ActionBazaarShippingRequest ob-
ject has the data sent by ActionBazaar to Turtle for fulfilling the shipping request. Next,
the method converts the data in the ActionBazaarShippingRequest object into a
TurtleShippingRequest . Transforming data like this is very common and ne-
cessary to get the data into Turtle's database for processing. Finally, the EntityManager
is used to save the data to Turtle's database . Remember, you'll learn more about the
EntityManager and JPA starting with chapter 9 .
Next, we'll examine the major MDB features by analyzing this code in greater detail, start-
ing with the @MessageDriven annotation.
4.3.4. Using the @MessageDriven annotation
MDBs are one of the simplest kinds of EJBs to develop, and they support the smallest num-
ber of annotations. The @MessageDriven annotation and the @ActivationCon-
figProperty annotation nested inside it are the only MDB-specific annotations. The
@MessageDriven annotation in the example represents what you'll use most of the
time. The annotation is defined as follows:
@Target(value = {ElementType.TYPE})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface MessageDriven {
String name() default "";
Class messageListenerInterface default Object.class;
ActivationConfigProperty[] activationConfig() default {};
String mappedName();
String description();
}
Search WWH ::




Custom Search