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.

Writing Simple JMS Client Applications<br />

920<br />

Destination type is topic<br />

To end program, type Q or q, then <br />

Reading message: This is message 1<br />

Reading message: This is message 2<br />

Reading message: This is message 3<br />

Message is not a TextMessage<br />

<strong>The</strong> last line appears because the program has received the non-text control message sent by<br />

the Producer program.<br />

3. Type Q or q and press Return to stop the program.<br />

4. Now run the programs using a queue. In this case, as with the synchronous example, you<br />

can run the Producer program first, because there is no timing dependency between the<br />

sender and receiver:<br />

appclient -client producer.jar queue 3<br />

<strong>The</strong> output of the program looks like this:<br />

Destination type is queue<br />

Sending message: This is message 1<br />

Sending message: This is message 2<br />

Sending message: This is message 3<br />

5. Run the AsynchConsumer program:<br />

appclient -client asynchconsumer.jar queue<br />

<strong>The</strong> output of the program looks like this:<br />

Destination type is queue<br />

To end program, type Q or q, then <br />

Reading message: This is message 1<br />

Reading message: This is message 2<br />

Reading message: This is message 3<br />

Message is not a TextMessage<br />

6. Type Q or q to stop the program.<br />

A Simple Example of Browsing Messages in a Queue<br />

This section describes an example that creates a QueueBrowser object to examine messages on a<br />

queue, as described in “JMS Queue Browsers” on page 905. This section then explains how to<br />

compile, package, and run the example using the Application Server.<br />

<strong>The</strong> following sections describe the steps in creating and running the example:<br />

■ “Writing the Client Program for the Queue Browser Example” on page 921<br />

■ “Compiling and Packaging the MessageBrowser Client” on page 922<br />

■ “Running the Clients for the Queue Browser Example” on page 922<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

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

Saved successfully!

Ooh no, something went wrong!