Use MQTT topic structure for IoT messaging
MQTT topics use slash-separated hierarchies with wildcards for subscription. Learn topic design, QoS levels, and retained messages.
- 1
MQTT topics are slash-separated hierarchical paths: home/livingroom/temperature. They are case-sensitive and must not start or end with /. Wildcards: + matches one level (home/+/temperature), # matches all remaining levels (home/# — must be last). Subscribers use wildcards; publishers always publish to a specific topic.
- 2 URL Parser →
Parse an MQTT topic like a URL path to understand its hierarchy. Split on / to get the topic levels. This helps validate topic structure and design hierarchical naming schemes for IoT devices.
- 3 URL Encoder →
Encode special characters in MQTT topics. Topics can contain spaces and UTF-8 characters, but they should be URL-encoded for safety. Avoid leading spaces, which are valid but confusing. Use lowercase with hyphens for consistency.
Frequently asked questions
- What are MQTT QoS levels?
- QoS 0: at most once (fire and forget, no acknowledgment). QoS 1: at least once (acknowledged, may duplicate). QoS 2: exactly once (four-step handshake, no duplicates). Use QoS 0 for frequent sensor data (duplicates don't matter), QoS 1 for commands, QoS 2 for critical messages (billing, state changes).
- What is a retained message?
- A retained message is the last message published to a topic, stored by the broker. New subscribers immediately receive the retained message on subscription. This is useful for state (device on/off, current temperature) — new clients get the current state without waiting for the next publish. Only one retained message per topic.
Workflows that solve this
Learn more
Want to understand why?