Home
Retained publications
By default, a broker deletes a publication when it has sent that publication to all the interested subscribers. This type of processing is suitable for event information, but is not always suitable for state information.
A publisher can specify that it wants the broker to keep a copy of a publication, which is then called a retained publication. The copy can be sent to subsequent subscribers who register an interest in the topic. This means that new subscribers don't have to wait for information to be published again before they receive it. For example, a subscriber registering a subscription to a stock price would receive the current price straightaway, without waiting for the stock price to change (and hence be re-published).
The broker retains only one publication for each topic, so the old publication is deleted when a new one arrives. It is recommended that you do not have more than one publisher sending retained publications on the same topic.
Subscribers can specify that they do not want to receive retained publications, and existing subscribers can ask for duplicate copies of retained publications to be sent to them.
When deciding whether to use retained publications, we need to consider several factors.
- Will your publications contain state information or event information?
Event publications do not usually have to be retained. For state information, if all the subscriptions to a topic are in place before any publications are made on that topic (and no new ones are expected), there is no need to retain publications because they will be delivered to all subscribers when they are published.
Another reason why publications might not need to be retained is if they are very frequent (for example, every second), because a new subscriber (or a subscriber recovering from a failure) receives the current state almost immediately after it subscribes.
- How will the subscriber application recover from a failure?
If the publisher does not use retained publications, the subscriber application might need to store its current state locally. If the publisher does use retained publications, the subscriber application can use the Request Update message to refresh its state information after a restart.
Note that the broker will continue to send publications to a registered subscriber even if that subscriber is not running. This could lead to a buildup of messages on the subscriber queue, which can be avoided if the subscriber registers with the 'Publish on Request Only' option. The subscriber must then refresh its state periodically using the Request Update command message. Note that in this case the subscriber does not receive any non-retained publications.
- What are the performance implications of retaining publications?
The broker needs to write retained publications to disk during the Publish request, which reduces throughput. If the publications are very large, a considerable amount of queue space (and hence disk space) is needed to store the retained publication of each topic. In a multi-broker environment, retained publications are also stored by all other brokers in the network that have a matching subscription.
Home