EXAMPLE 1

4.3 Consumer Tool

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:

  1. Consumer connects to the message server specifying the URL. In our example, it is tcp://localhost:61616.
  2. Consumer creates a session specifying the queue it would like to read from.
  3. It then creates a consumer that will read messages from the queue specified in step 2.
  4. 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.
  5. 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.