Java Reference
In-Depth Information
You will find the source files for this section in the tut-install /examples/jms/cli-
entmdbentity/ directory. Path names in this section are relative to this directory.
Overview of the clientmdbentity Example Application
This application simulates, in a simplified way, the work flow of a company's human re-
sources (HR) department when it processes a new hire. This application also demonstrates
how to use the Java EE platform to accomplish a task that many JMS applications need to
perform.
A JMS client must often wait for several messages from various sources. It then uses the
information in all these messages to assemble a message that it then sends to another des-
tination. The common term for this process is joining messages . Such a task must be trans-
actional, with all the receives and the send as a single transaction. If not all the messages
are received successfully, the transaction can be rolled back. For an application client ex-
ample that illustrates this task, see “ A Local Transaction Example on page 411 .
A message-driven bean can process only one message at a time in a transaction. To
provide the ability to join messages, an application can have the message-driven bean
store the interim information in an entity. The entity can then determine whether all the
information has been received; when it has, the entity can report this back to one of the
message-driven beans, which then creates and sends the message to the other destination.
After it has completed its task, the entity can be removed.
The basic steps of the application are as follows.
1. The HR department's application client generates an employee ID for each new
hire and then publishes a message (M1) containing the new hire's name, employee
ID, and position. The client then creates a temporary queue, ReplyQueue , with
a message listener that waits for a reply to the message. (See “ Creating Temporary
Destinations on page 363 for more information.)
2. Two message-driven beans process each message: One bean, OfficeMDB , as-
signs the new hire's office number, and the other bean, EquipmentMDB , assigns
the new hire's equipment. The first bean to process the message creates and per-
sists an entity named SetupOffice , then calls a business method of the entity to
store the information it has generated. The second bean locates the existing entity
and calls another business method to add its information.
3. When both the office and the equipment have been assigned, the entity business
method returns a value of true to the message-driven bean that called the method.
The message-driven bean then sends to the reply queue a message (M2) describing
Search WWH ::




Custom Search