background image

Using the JMS API with an Entity

<< Building the clientsessionmdb Example | HR Department Application >>
<< Building the clientsessionmdb Example | HR Department Application >>

Using the JMS API with an Entity

ant clean
A Java EE Application That Uses the JMS API with an Entity
This section explains how to write, compile, package, deploy, and run a Java EE application that
uses the JMS API with an entity. The application uses the following components:
An application client that both sends and receives messages
Two message-driven beans
An entity class
This section covers the following topics:
"Overview of the clientmdbentity Example Application" on page 970
"Writing the Application Components for the clientmdbentity Example" on page 972
"Creating Resources for the clientmdbentity Example" on page 974
"Building, Deploying, and Running the clientmdbentity Example Using NetBeans IDE" on
page 975
"Building, Deploying, and Running the clientmdbentity Example Using Ant" on page 977
You will find the source files for this section in the directory
tut-install/javaeetutorial5/examples/jms/clientmdbentity/. 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 resources
(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 client applications 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
destination. The common term for this process is joining messages. Such a task must be
transactional, 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 a client example that illustrates this
task, see
"A Local Transaction Example" on page 949
.
A message-driven bean can process only one message at a time in a transaction. To provide the
ability to join messages, a Java EE 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.
A Java EE Application That Uses the JMS API with an Entity
The Java EE 5 Tutorial · September 2007
970