Case File: Who Hears the Message
A depot network sends sensor messages through an MQTT broker, and some dashboards get messages that they should not, while others miss the ones they need. Work out which clients receive each topic from their subscription filters with the exact rules: + is one level, # is the rest and may match nothing, empty levels count, system topics are not matched by a leading wildcard, and invalid filters or publish topics are reported. Run it on brokers that you cannot see. The broker is generated for you alone.
Sabi Logistics · Fleet 1
Who Hears the Message
The alerts dashboard shows the temperature of a depot that it should not see, and the map misses every locker that reports its battery
Kemi Product owner ·
Kemi. Two things are wrong with the depot dashboards and Tunde says that both come from the topic filters. The alerts screen is showing readings from the Kano depot, which is a different team’s. And the map shows no battery level for any locker, although they report it.
I cannot read the subscription list, but I have it in a file: each client and the filter that it uses, and the topics that devices published to. Please work out who receives which topic, which topics nobody receives, which filters are not valid, and which client receives the most.
The brief
What you need to know first.
- Topics and levels. A topic is names separated by slashes:
depot/abuja/temphas three levels. Empty levels count:depot//temphas three levels with an empty one in the middle, and a leading slash (/depot) adds an empty first level. - The two wildcards (in filters only).
+stands for exactly one level:depot/+/tempmatchesdepot/kano/tempbut notdepot/kano/gps/temp.#stands for any number of levels, including none, and must be the last level:depot/#matchesdepot,depot/abujaanddepot/abuja/temp. - Traps. A filter that starts with
#or+does not match a topic that starts with$(system topics such as$SYS/broker/uptime);$SYS/#does. A filter is invalid when#is not the last level, when+or#shares a level with other characters (depot/ab+/temp), or when it is empty: ignore it and list it inbad_filters. A publish topic is invalid when it is empty or contains+or#: devices may not publish to a wildcard. - The routing. Look at each different published topic once.
deliveries[topic]is the sorted list of clients with a valid filter that matches it (each client once, even if two of its filters match).unmatchedlists valid topics that nobody receives.busiestis the client that receives the most different topics (a tie goes to the name that sorts first,Noneif nobody receives anything). - Fill in
valid_filter,match,route(req), thenresultandbusiest. The checks runrouteon brokers that you cannot see:sport/#matchingsport,$SYStopics, a leading slash, and an empty broker.
The lab gives you the data for this case, invented and generated for you alone.
Preparing your data…
On the bench
The lab checked the rule with a script. These are the tools and checks that show the same thing on a real broker, device or fleet.
| You want to | Do this | What you see |
|---|---|---|
| see which clients receive a topic on a real broker | Subscribe with mosquitto_sub -t "depot/#" -v on a test broker that you own, then publish with mosquitto_pub | every message with its topic, to compare with your routing result |
| list what a client is allowed to subscribe to | Read the broker ACL file or the access policy of your cloud broker | the topic patterns each client may publish and subscribe to |
| check that a client cannot subscribe to everything | Try mosquitto_sub -t "#" with an ordinary client account on your test broker | a refusal or an empty result if the access control is right |
Only connect to brokers, devices and networks that you own or have written permission to test.
Kemi: “I understand now: the alerts filter was #, which matches everything. But how do we stop somebody subscribing to everything again?”
🔒 The debrief unlocks when you close the case. Finish the lab above.
The debrief
Kemi: “So the filter is a permission, not only a convenience.”
What a senior IoT engineer would do next. Treat topics as a namespace with owners: depot/<site>/<device>/<measure>, with the site early so that a team can be given depot/abuja/# and nothing else. Enforce it with access control lists on the broker (the broker refuses a subscribe to # from an ordinary client), not by trust. Put no personal or secret data in topic names, since topics are visible to many. Use one device id per level, never put data in the topic that belongs in the payload, and avoid a leading slash and empty levels. Test the topic design with a table of publishes and subscriptions like this one, in a unit test, so that a new filter cannot quietly widen who sees what. And remember that # at the top level on a busy broker is a load problem as well as a privacy problem.
The trap. Reading depot/+ as “everything under depot”. It matches one level only: depot/abuja yes, depot/abuja/temp no.
Write the topic routing note
Write the note for the product owner: how filters match topics (+ is one level, # is the rest and may match nothing, empty levels count, system topics are not matched by a leading wildcard), who receives each topic in the broker of the case and which topics nobody receives, which filters are invalid and why, why the alerts dashboard saw another team's depot and the map missed the battery (a filter that was too wide and one that was one level off), and how to prevent it (a topic namespace with owners, access control lists on the broker, tests with a table of publishes and subscriptions).
🧪 Want to practise this on your own computer? See how to set up your lab →