Durable subscribers
A durable subscriber is a message consumer that receives all messages published on a topic, including messages published while the subscriber is inactive.
The information in this topic is relevant only if an application connects to an IBM MQ queue manager or a WebSphere Application Server service integration bus. The information is not relevant for a real-time connection to a broker.
To create a durable subscriber for a topic, an application calls the Create Durable Subscriber method of a Session object, specifying as parameters a name that identifies the durable subscription and a Destination object representing the topic. The application can create a durable subscriber with or without a message selector, and it can specify whether the durable subscriber is to receive messages published by its own connection.
The session used to create a durable subscriber must have an associated client identifier. The client identifier is the same as that associated with the connection that is used to create the session; it is specified as described in ConnectionFactories and Connection objects.
The name that identifies the durable subscription must be unique within the client identifier, and therefore the client identifier forms part of the full, unique identifier of the durable subscription. The messaging server maintains a record of the durable subscription and ensures that all messages published on the topic are retained until they are acknowledged by the durable subscriber or they expire.
The messaging server continues to maintain the record of the durable subscription even after the durable subscriber closes. To reuse a durable subscription that was created previously, an application must create a durable subscriber specifying the same subscription name, and using a session with the same client identifier, as those associated with the durable subscription. Only one session at a time can have a durable subscriber for a particular durable subscription.
The scope of a durable subscription is the messaging server that is maintaining a record of the subscription. If two applications connected to different messaging servers each create a durable subscriber using the same subscription name and client identifier, two completely independent durable subscriptions are created.
To delete a durable subscription, an application calls the Unsubscribe method of a Session object, specifying as a parameter the name that identifies the durable subscription. The client identifier associated with the session must be the same as that associated with the durable subscription. The messaging server deletes the record of the durable subscription that it is maintaining and does not send any more messages to the durable subscriber.
To change an existing subscription, an application can create a durable subscriber using the same subscription name and client identifier, but specifying a different topic, or message selector (or both). Changing a durable subscription is equivalent to deleting the subscription and creating a new one.
For an application that connects to IBM WebSphere MQ Version 7.0 or later queue manager, XMS manages the subscriber queues. Hence the application is not required to specify a subscriber queue. XMS will ignore the subscriber queue if specified.
Note that we cannot change the subscriber queue for a durable subscription. The only way to change the subscriber queue is to delete the subscription and create a new one.
For an application that connects to a service integration bus, each durable subscriber must have a designated durable subscription home. To specify the durable subscription home for all durable subscribers that use the same connection, set the XMSC_WPM_DUR_SUB_HOME property of the ConnectionFactory object that is used to create the connection. To specify the durable subscription home for an individual topic, set the XMSC_WPM_DUR_SUB_HOME property of the Destination object representing the topic. A durable subscription home must be specified for a connection before an application can create a durable subscriber that uses the connection. Any value specified for a destination overrides the value specified for the connection.
Parent topic: Message consumers