A MessageConsumer object is created by a Session object and is used for receiving messages sent to destinations. For example, using the mySession
object created in Session, the following creates a MessageConsumer that retrieves messages from a queue named myQueue
:
For queues, messages remain on the queue until they are consumed by a MessageConsumer, the message expiration time has been reached, or the maximum size of the queue is reached.
The following sections describe how message consumers can obtain messages.
Only MessageConsumers whose client applications are running receive messages published on a topic. Optionally, Sessions can create durable subscribers to ensure that messages are received, even if the application is not currently running.
Use the Session.createDurableSubscriber()
method to create a durable subscription. Messages are stored by the server as long as durable subscribers exist for the topic, or until the message expiration time for the message has been reached, or until the storage limit has been reached for the topic.
When an application restarts and recreates a durable subscriber with the same ID, all messages stored on the server for that topic are published to the durable subscriber.
For more information on using the createDurableSubscriber()
method, see the TIBCO Enterprise Message Service Java API Reference.
The API allows for synchronous or asynchronous message consumption. For synchronous consumption, the MessageConsumer explicitly calls the receive()
method on the topic or queue. For asynchronous consumption, the client registers a MessageListener for the topic or queue. When a message arrives at the destination, the TIBCO Enterprise Message Service server delivers the message by calling the listener’s onMessage()
method.
TIBCO Enterprise Message Service™ User’s Guide Software Release 4.3, February 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |