The Topic Router is the heart of the broker’s pub/sub. Every published message is matched against the set of active subscriptions and delivered to the clients whose topic filters match — in both directions, telemetry going up and commands coming down.
Topic shape
Telemetry flows on devices/{deviceId}/telemetry/# and commands flow on
devices/{deviceId}/commands. Keeping device id high in the hierarchy lets
the router prune whole branches of the match trie quickly.
Subscriptions are kept in a topic trie so that a single publish can be matched against millions of filters without scanning them linearly. Wildcards are handled at the node level:
devices/+/telemetry matches one segment — every device’s telemetry root, but
not nested sub-topics.