EXAMPLE 1
The consumer tool spawns a
thread that reads messages from a specified queue at a URL that indicates the
message service socket. The actions performed by the consumer are as follows:
- Consumer connects to the
message server specifying the URL. In our example, it is tcp://localhost:61616.
- Consumer creates a session
specifying the queue it would like to read from.
- It then creates a consumer
that will read messages from the queue specified in step 2.
- This consumer class is set
as the MessageListener so that messages when fetched can be delivered to it
for further processing. onMessage () method handles the message after
retrieval.
- Finally the consumer can
shut down after closing the consumer, session and connection with the
message server.
Output after running the Consumer Tool is
here.