IoT Engineer

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.

50 min

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/temp has three levels. Empty levels count: depot//temp has 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/+/temp matches depot/kano/temp but not depot/kano/gps/temp. # stands for any number of levels, including none, and must be the last level: depot/# matches depot, depot/abuja and depot/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 in bad_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). unmatched lists valid topics that nobody receives. busiest is the client that receives the most different topics (a tie goes to the name that sorts first, None if nobody receives anything).
  • Fill in valid_filter, match, route(req), then result and busiest. The checks run route on brokers that you cannot see: sport/# matching sport, $SYS topics, 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 toDo thisWhat you see
see which clients receive a topic on a real brokerSubscribe with mosquitto_sub -t "depot/#" -v on a test broker that you own, then publish with mosquitto_pubevery message with its topic, to compare with your routing result
list what a client is allowed to subscribe toRead the broker ACL file or the access policy of your cloud brokerthe topic patterns each client may publish and subscribe to
check that a client cannot subscribe to everythingTry mosquitto_sub -t "#" with an ordinary client account on your test brokera 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.

🔒 The debrief unlocks when you close the case. Finish the lab above.

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).

0 words

🧪 Want to practise this on your own computer? See how to set up your lab →

📝

Knowledge Check

1 of 4

What does the filter depot/+/temp match?

Report a problem

About: /lessons/case-the-wildcard