Retained publications and MQTT clients

A topic can have one, and only one, retained publication. If you create a subscription to a topic that has a retained publication, the publication is immediately forwarded to you.

Use the MqttMessage.setRetained method to specify whether a publication on a topic is retained.

When you create or update a retained publication, send the publication with a QoS of 1 or 2. If you send it with a QoS of 0, IBM® MQ creates a nonpersistent retained publication. The publication is not retained if the queue manager stops.

If you publish a non-retained publication to a topic that has a retained publication, the retained publication is not affected. Current subscribers receive the new publication. New subscribers receive the retained publication first, then receive any new publications.

You can use a retained publication to record the latest value of a measurement. New subscribers to a topic immediately receive the most recent value of the measurement. If no new measurements are taken since the subscriber last subscribed to the publication topic, and if the subscriber subscribes again, the subscriber receives the most recent retained publication on the topic again.

To delete a retained publication, you have two options:
  • Run the CLEAR TOPICSTR MQSC command.
  • [V8.0.0.5 May 2016]Create a zero-length retained publication. As specified in the MQTT 3.1.1 specification, if a zero-length retained message is published to a topic, any retained message for that topic is cleared.