A MessageListener object acts as an asynchronous event handler for messages. This object implements the MessageListener interface and has one method, onMessage()
.
The onMessage()
method is called by the TIBCO Enterprise Message Service server when a message arrives on a destination. You implement the onMessage()
method in your MessageListener class to perform the desired actions when a message arrives. Your implementation should handle all exceptions, and it should not throw any exceptions.
Once you create a MessageListener object, you must register it with a specific MessageConsumer. For example, using the myQueueReceiver
object created in MessageConsumer, the following creates a queueListener (an implementation of the MessageListener interface) and registers it with the QueueReceiver object:
MessageListener queueListener = new MessageListener(); myQueueReceiver.setMessageListener(queueListener);
You should register the MessageListener with the MessageConsumer before calling the Connection’s start()
method to begin receiving messages.
A MessageListener is not specific to the type of the destination. The same listener can obtain messages from a queue or a topic depending upon whether the MessageConsumer that registered the listener is a TopicSubscriber or a QueueReceiver.
The J2EE 1.3 platform introduced message-driven beans (MDBs) that are a special kind of MessageListener. See the J2EE documentation for more information about MDBs.
TIBCO Enterprise Message Service™ User’s Guide Software Release 4.3, February 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |