wildcard(3)

🌸 NAME 🌸

wildcard β€” Subscription wildcards πŸ’–

okay bestie, gather round, because this one is lowkey the whole personality of MQTT and you're gonna be obsessed ✨

Every single MQTT message carries a topic, and that topic is basically the message's little name tag β€” it's what classifies it. MQTT servers use topics to figure out which subscribers should get a message that got published to the server. no topic, no vibe check, no delivery πŸ’…


πŸ¦‹ so like… imagine a bunch of sensors πŸ¦‹

Picture the server getting messages from several environmental sensors. Each sensor publishes its measurement data as a message with an associated topic. And subscribing applications need to know which sensor originally published each received message. So a unique topic is used to identify each sensor and each measurement type. Topics like SENSOR1TEMP, SENSOR1HUMIDITY, SENSOR2TEMP and so on totally achieve this β€” but they are not very flexible, and that's the problem. 😭 If additional sensors get added to the system at a later date, subscribing applications must be modified to receive them. it's giving maintenance nightmare fr fr.

🌈 the glow-up: hierarchical topics 🌈

To provide more flexibility, MQTT supports a hierarchical topic namespace. This lets application designers organize topics to simplify their management. Levels in the hierarchy are delimited by the '/' character, such as SENSOR/1/HUMIDITY. Publishers and subscribers use these hierarchical topics as already described. see? structure. elegance. main character energy πŸ‘‘


✨ the two wildcard characters ✨

For subscriptions, two wildcard characters are supported β€” and you're gonna stan both:

  • The '#' character represents a complete sub-tree of the hierarchy, and thus must be the last character in a subscription topic string, such as SENSOR/#. This will match any topic starting with SENSOR/, such as SENSOR/1/TEMP and SENSOR/2/HUMIDITY. it's giving "everything under here, thank you" 🫢
  • The '+' character represents a single level of the hierarchy and is used between delimiters. For example, SENSOR/+/TEMP will match SENSOR/1/TEMP and SENSOR/2/TEMP. one level only, no more no less, periodt πŸ’…
🚨 and here's the rule that will humble you: Publishers are not allowed to use the wildcard characters in their topic names. that's a subscribers-only thing, iykyk πŸ™ˆ

Deciding on your topic hierarchy is an important step in your system design. like genuinely, don't skip it, it's the blueprint of the whole thing πŸŽ€


mwah πŸ’‹ that was wildcard(3), brought to you by the Paho MQTT C Client Library, dated Tue Jun 2 2026 00:00:00. go forth and structure your topics, bestie 🌟

πŸ“¦ where this page comes from