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 send the message to other consumers or notify one or more components.

JMS message listeners implement the javax.jms.MessageLintener interface and can be either client-side listener objects or EJB 2.0 message-driven beans (MDB). The MessageListener interface 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, notify component
   }
}

You can use EAServer Manager to install a message listener on a message queue or topic—see “Installing and configuring an MDB”. You can also install a message listener within your application. First create a message consumer, see “Creating message consumers”, then install the listener, using this syntax:

receiver.setMessageListener(new QueueMessageListener());