Creating message consumers

Message consumers can be either QueueReceiver or TopicSubscriber objects. Create a QueueReceiver to retrieve messages that are sent using the PTP messaging model. Use previously created Queue and QueueSession objects, as follows:

javax.jms.QueueReceiver receiver =
   queueSession.createReceiver(queue);

A TopicSubscriber object receives published messages and can be either durable or nondurable. A nondurable subscriber can only receive published messages while it is connected to EAServer. If you want guaranteed message delivery, make the subscriber durable. For example, if you create a durable subscription on a topic, EAServer saves all published messages for the topic in a database. If a durable subscriber is temporarily disconnected from EAServer, its messages will be delivered when the subscriber is reconnected. The messages are deleted from the database only after they are delivered to the durable subscriber.

This example illustrates how to create both durable and nondurable topic subscribers. In both cases, you need to reference previously created Topic and TopicSession objects:

// Create a durable subscriber

javax.jms.TopicSubscriber subscriber = 
   topicSession.createDurableSubscriber(topic,
                                   “subscriptionName”)

// Create a non-durable subscriber

javax.jms.TopicScuscriber subscriber =
   topicSession.createSubscriber(topic);

To remove a durable topic subscription, call the TopicSession.unsubscribe method, and pass in the subscription name; for example:

topicSession.unsubscribe(“subscriptionName”);