In this episode of MQTT Essentials series, we will talk about MQTT Retained Messages.
👉 What is a Retained Message in MQTT?
A retained message in MQTT is a topic's last known good value persisted by the broker. The broker stores the last retained message and the corresponding QoS for that topic. Each client that subscribes to a topic pattern that matches the topic of the retained message receives the retained message immediately after they subscribe. The broker stores only one retained message per topic.
Retained messages
- are useful when a start state is required
- ensure that clients get the last stored value immediately after subscription
Sending retained messages
From the perspective of a developer, sending a retained message is quite simple and straight-forward. You just set the retained flag of an MQTT publish message to true. Typically, your client library provides an easy way to set this flag.
- subscribers receive the message immediately (even if they were offline when the message was published)
- this solves the empty start value problem
- only one retained message per topic is stored by the broker
Queued vs. retained messages
Retained messages: work on a topic level, newly-connected subscribers to a topic receive messages immediately
Queued messages: work in a client context, the broker queues undelivered messages for a specific client
Deleting retained messages:
- not necessary in most cases
- a new retained message overwrites the old one
- to delete: send a retained message with an empty payload
*** Chapters / Table of Contents ***
00:00 Introduction to MQTT Retained Messages
00:22 What is a Retained Message in MQTT?
01:07 Sending retained messages in MQTT
02:08 Queued vs. retained messages in MQTT
03:41 How to delete a retained message in MQTT
04:31 Announcing part 10 - Last Will & Testament in MQTT
👉 If you missed Part 1 - What is MQTT, watch it now: [ Ссылка ]
👉 We also explain the MQTT Retained Messages in detail in the HiveMQ blog here: [ Ссылка ]
👉 We also explain the core of MQTT concepts, its features, and other essential information on the HiveMQ blog: [ Ссылка ]
👉 Get your own MQTT Essentials in a comprehensive, free E-Book: [ Ссылка ]
👉 To know about HiveMQ: [ Ссылка ]
Subscribe to our HiveMQ channel to get video updates. Hit the subscribe button above or subscribe to our newsletter ([ Ссылка ]) to keep up to date on the latest MQTT news.
👉 We're looking forward to seeing you next week for MQTT Essentials part 10 - Last Will & Testament. [ Ссылка ]
#MQTT #MQTTEssentials #MQTTMonday #IoT
MQTT Retained messages | MQTT Essentials Part 9
Теги
MQTTMQTT EssentialsMQTT MondayIoTInternet of ThingsIoT protocolHiveMQMQTT ExplanationMQTT TutorialMQTT ProtocolMQTT Brokerpublish subscribeMQTT ClientMQTT MessageMQTT Connectionunsubscribe MQTTMQTT TopicMQTT WildcardsMQTT QoSQoS 1QoS 2QoS 0Quality of Service MQTTMessage Queueing MQTTMessage QueueingRetained Messages MQTTWhat is MQTT?Basics of MQTTSending retained messages in MQTTRetained Messages in MQTT