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 />

914<br />

<strong>The</strong> result, however, is different. Because you are using a topic, messages that were sent<br />

before you started the consumer cannot be received. (See “Publish/Subscribe Messaging<br />

Domain” on page 895, for details.) Instead of receiving the messages, the program<br />

appears to hang.<br />

7. Run the Producer example again. Right-click the producer project and choose Run.<br />

Now the SynchConsumer example receives the messages:<br />

Destination type is topic<br />

Reading message: This is message 1<br />

Reading message: This is message 2<br />

Reading message: This is message 3<br />

You can also run the sample programs using the appclient command. Each of the programs<br />

takes one or more command-line arguments: a destination type and, for Producer, a number of<br />

messages.<br />

To run the clients using the appclient command, follow these steps:<br />

1. In a terminal window, go to the producer/dist directory:<br />

cd ../producer/dist<br />

2. Run the Producer program, sending three messages to the queue:<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 />

<strong>The</strong> messages are now in the queue, waiting to be received.<br />

3. In the same window, go to the synchconsumer/dist directory:<br />

cd ../../synchconsumer/dist<br />

4. Run the SynchConsumer program, specifying the queue:<br />

appclient -client synchconsumer.jar queue<br />

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

Destination type is queue<br />

Reading message: This is message 1<br />

Reading message: This is message 2<br />

Reading message: This is message 3<br />

5. Now try running the programs in the opposite order. Run the SynchConsumer program. It<br />

displays the destination type and then appears to hang, waiting for messages.<br />

appclient -client synchconsumer.jar queue<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!