background image

Coding the Application Client

<< Using the JMS API with a Session Bean | Coding the Publisher Session Bean >>
<< Using the JMS API with a Session Bean | Coding the Publisher Session Bean >>

Coding the Application Client

The Publisher enterprise bean in this example is the enterprise-application equivalent of a
wire-service news feed that categorizes news events into six news categories. The
message-driven bean could represent a newsroom, where the sports desk, for example, would
set up a subscription for all news events pertaining to sports.
The application client in the example injects the Publisher enterprise bean's remote home
interface and then calls the bean's business method. The enterprise bean creates 18 text
messages. For each message, it sets a String property randomly to one of six values
representing the news categories and then publishes the message to a topic. The message-driven
bean uses a message selector for the property to limit which of the published messages it
receives.
Writing the components of the application involves the following:
"Coding the Application Client: MyAppClient.java" on page 965
"Coding the Publisher Session Bean" on page 966
"Coding the Message-Driven Bean: MessageBean.java" on page 967
Coding the Application Client: MyAppClient.java
The application client program,
clientsessionmdb-app-client/src/java/MyAppClient.java
, performs no JMS API
Topic
Java EE Server
MDB Instance
EJB
Container
Application
Client
Session Bean
EJB
Container
Msg
Msg
Calls
Publishes
Delivers
FIGURE 32­1
A Java EE Application: Client to Session Bean to Message-Driven Bean
A Java EE Application That Uses the JMS API with a Session Bean
Chapter 32 · Java EE Examples Using the JMS API
965