Create durable topic subscribers

 

We cannot create a durable topic subscriber if the transport type is direct.

Durable topic subscribers are used when an application needs to receive messages that are published even while the application is inactive.

Creating a durable topic subscriber is similar to creating a nondurable message consumer, but also provide a name that identifies the durable subscription, as in the following example:

// Create a durable subscriber, supplying a uniquely-identifying name
TopicSubscriber sub = session.createDurableSubscriber( topic, "D_SUB_000001" );

The session used to create a durable topic subscriber must have an associated client identifier. The name that identifies a durable subscription must be unique only within the client identifier, and therefore the client identifier forms part of the full, unique identifier of the durable subscription. To reuse a durable subscription that was created previously, an application must create a durable topic subscriber using a session with the same client identifier as that associated with the durable subscription.

The client identifier associated with a session is the same as that associated with the connection that is used to create the session. The client identifier can be specified by setting the CLIENTID property of the ConnectionFactory object. Alternatively, an application can specify the client identifier by calling the setClientID() method of the Connection object. For more information about client identifiers and their relationship with durable topic subscribers and durable subscriptions, see the Java™ Message Service Specification, Version 1.1.

A durable topic subscriber is created for the queue manager specified by the QMANAGER property of the ConnectionFactory object. If there is a subsequent attempt to create a durable topic subscriber with the same name for a different queue manager, a new and completely independent durable topic subscriber is returned.

Nondurable message consumers in the publish/subscribe domain automatically deregister themselves when their close() method is called, or when they fall out of scope. However, if you want to terminate a durable subscription, you must explicitly notify the broker. To do this, use the unsubscribe() method of the session and pass in the name that identifies the durable subscription:

// Unsubscribe the durable subscriber created above
session.unsubscribe( "D_SUB_000001" );


uj25110_