background image

Asynchronous Message Consumption

<< The appclient Command | The TextListener Class >>
<< The appclient Command | The TextListener Class >>

Asynchronous Message Consumption

Destination type is topic
Sending message: This is message 1
Sending message: This is message 2
Sending message: This is message 3
8. Now run the SynchConsumer program using the topic:
appclient -client synchconsumer.jar topic
The result, however, is different. Because you are using a topic, messages that were sent
before you started the consumer cannot be received. (See
"Publish/Subscribe Messaging
Domain" on page 899
, for details.) Instead of receiving the messages, the program appears
to hang.
9. Run the Producer program again. Now the SynchConsumer program receives the messages:
Destination type is topic
Reading message: This is message 1
Reading message: This is message 2
Reading message: This is message 3
Because the examples use the common interfaces, you can run them using either a queue or a
topic.
A Simple Example of Asynchronous Message
Consumption
This section describes the receiving programs in an example that uses a message listener to
consume messages asynchronously. This section then explains how to compile and run the
programs using the Application Server.
The following sections describe the steps in creating and running the example:
"Writing the Client Programs for the Asynchronous Receive Example" on page 920
"Compiling and Packaging the AsynchConsumer Client" on page 922
"Running the Clients for the Asynchronous Receive Example" on page 923
Writing the Client Programs for the Asynchronous Receive Example
The sending program is producer/src/java/Producer.java, the same program used in the
example in
"A Simple Example of Synchronous Message Receives" on page 911
.
An asynchronous consumer normally runs indefinitely. This one runs until the user types the
letter q or Q to stop the program.
Writing Simple JMS Client Applications
The Java EE 5 Tutorial · September 2007
920