Configure durable topic subscribers

 

As stated previously, there might still be good reasons to use the multiple queue approach for durable topic subscribers. Durable topic subscribers are likely to have a longer life span, and so it is possible for a large number of messages for a durable subscriber to accumulate on a queue.

The name of the consumer queue for a durable topic subscriber is a property of a Topic object. This allows you to specify a number of different consumer queue names without having to create multiple objects starting from a ConnectionFactory object.

We can specify the name of the consumer queue for durable topic subscribers in either of the following ways:

The queue name you provide must start with the following characters:

To use the shared queue approach, specify the complete name of the shared queue. The queue must exist before we can create a subscription.

To use the multiple queue approach, specify a queue name that ends with an asterisk (*). Subsequently, when an application creates a durable topic subscriber specifying this queue name, WebSphere MQ JMS creates a permanent dynamic queue for exclusive use by that subscriber. With the multiple queue approach, therefore, all the required queues are created dynamically.

Here is an example of using the multiple queue approach:

// Set the MQTopic durable subscriber queue name using
// the multi-queue approach
sportsTopic.setBrokerDurSubQueue("SYSTEM.JMS.D.FOOTBALL.*");
After the Topic object is initialized, it can be passed into the createDurableSubscriber() method of a Session object to create a durable topic subscriber:
// Create a durable subscriber using our earlier Topic
TopicSubscriber sub = session.createDurableSubscriber(sportsTopic,
                                                      "D_SUB_SPORT_001");

If you use the multiple queue approach, we cannot specify the complete name of a queue, only a prefix. This allows you to create different domains of consumer queues. For example, we can use:

The characters that precede the asterisk (*) are used as the prefix, so that all dynamic queues for durable topic subscribers specifying this prefix have queue names that start with SYSTEM.JMS.D.MYDOMAIN.

We cannot change the consumer queue of a durable topic subscriber. If, for example, you want to move from the multiple queue approach to the single queue approach, first delete the old subscriber using the unsubscribe() method and then create a new subscriber. Deleting the old subscriber also deletes any unconsumed messages for that subscriber.


uj25170_