Asynchronous Message Consumption
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
, 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
The sending program is producer/src/java/Producer.java, the same program used in the
example in
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