10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

FIGURE 32–1 A <strong>Java</strong> <strong>EE</strong> Application: Client to Session Bean to Message-Driven Bean<br />

Calls<br />

Application<br />

Client<br />

Session Bean<br />

EJB<br />

Container<br />

<strong>Java</strong> <strong>EE</strong> Server<br />

Topic<br />

MDB Instance<br />

<strong>The</strong> Publisher enterprise bean in this example is the enterprise-application equivalent of a<br />

wire-service news feed that categorizes news events into six news categories. <strong>The</strong><br />

message-driven bean could represent a newsroom, where the sports desk, for example, would<br />

set up a subscription for all news events pertaining to sports.<br />

<strong>The</strong> application client in the example injects the Publisher enterprise bean’s remote home<br />

interface and then calls the bean’s business method. <strong>The</strong> enterprise bean creates 18 text<br />

messages. For each message, it sets a String property randomly to one of six values<br />

representing the news categories and then publishes the message to a topic. <strong>The</strong> message-driven<br />

bean uses a message selector for the property to limit which of the published messages it<br />

receives.<br />

Writing the components of the application involves the following:<br />

EJB<br />

Container<br />

Msg Msg<br />

Publishes Delivers<br />

■ “Coding the Application Client: MyAppClient.java” on page 957<br />

■ “Coding the Publisher Session Bean” on page 958<br />

■ “Coding the Message-Driven Bean: MessageBean.java” on page 959<br />

Coding the Application Client: MyAppClient.java<br />

A <strong>Java</strong> <strong>EE</strong> ApplicationThat Uses the JMS API with a Session Bean<br />

<strong>The</strong> application client program,<br />

clientsessionmdb-app-client/src/java/MyAppClient.java, performs no JMS API<br />

Chapter 32 • <strong>Java</strong> <strong>EE</strong> Examples Using the JMS API 957

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!