0
0
IOT Protocolsdevops~20 mins

Retained messages in IOT Protocols - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Retained Messages Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the main purpose of retained messages in MQTT?

In MQTT, retained messages serve a specific function. What is the main purpose of using retained messages?

ATo guarantee message delivery even if the subscriber is offline
BTo limit the message size to reduce bandwidth usage
CTo encrypt messages for secure transmission
DTo store the last message on a topic so new subscribers receive it immediately upon subscribing
Attempts:
2 left
💡 Hint

Think about what happens when a new device connects and wants the latest data.

💻 Command Output
intermediate
1:30remaining
What output does the MQTT broker produce after publishing a retained message?

Consider this MQTT publish command with the retain flag set:

mosquitto_pub -t 'home/temperature' -m '22' -r

What is the expected behavior of the broker regarding this message?

AThe broker stores '22' as the last retained message for 'home/temperature' and sends it to new subscribers immediately
BThe broker deletes any previous messages on 'home/temperature' and does not store the new message
CThe broker sends the message only to currently connected subscribers and discards it afterwards
DThe broker queues the message until the subscriber acknowledges receipt
Attempts:
2 left
💡 Hint

Retain flag means the broker keeps the message for future subscribers.

Troubleshoot
advanced
2:00remaining
Why might a subscriber not receive the retained message after subscribing?

A subscriber connects to the MQTT broker and subscribes to a topic with a retained message, but does not receive the retained message. Which of the following is the most likely cause?

AThe broker does not support retained messages and ignores the retain flag
BThe subscriber used a QoS level of 0, which disables retained messages
CThe retained message was cleared by publishing an empty retained message to the topic
DThe subscriber did not set the clean session flag to false
Attempts:
2 left
💡 Hint

Think about how retained messages can be removed from the broker.

🔀 Workflow
advanced
2:00remaining
Order the steps for setting a retained message and receiving it as a new subscriber

Arrange the following steps in the correct order to successfully publish a retained message and have a new subscriber receive it immediately.

A1,3,2,4
B1,2,3,4
C2,1,3,4
D3,1,2,4
Attempts:
2 left
💡 Hint

Think about what happens first: publishing, storing, subscribing, then delivery.

Best Practice
expert
2:30remaining
What is the best practice to update a retained message with new sensor data?

You have a temperature sensor publishing data to an MQTT topic with retained messages enabled. What is the best practice to update the retained message correctly?

APublish new readings with retain flag only if the temperature changes by more than 5 degrees.
BPublish each new temperature reading with the retain flag set to overwrite the previous retained message.
CPublish new readings with retain flag set to false and rely on subscribers to request the latest data.
DPublish new readings without the retain flag and periodically clear the retained message manually.
Attempts:
2 left
💡 Hint

Consider how retained messages keep the last known good value.