Implementing and installing message listeners

Message listeners allow you to receive messages asynchronously. Once you have implemented a listener, install it on a message consumer. When a message is delivered to the message consumer, the listener can process the message or send it to other consumers.

The message service implements two types of JMS message listeners:

A message listener implements the javax.jms.MessageListener interface, which contains only the onMessage method. This example illustrates the skeleton code for a message listener:

class QueueMessageListener implements MessageListener
{
   public void onMessage(javax.jms.Message msg)
   {
      // process message
   }
}

To install a client-side message listener, first create a message consumer (see “Creating message consumers”), then install the listener, using this syntax:

myConsumer.setMessageListener(new MessageListener());