MQTT Topic Wildcards?

HI,

Does the Cayenne MQTT broker support the topic wildcards “#” and “+”?

I’m wondering if I can subscribe to something like “v1/username/things/clientID/cmd/+”.

Hmmm. I have not tried wildcard… @rsiegel or @jburhenn do you know?

I just tried it and it does seem to work :slight_smile:

I’m late to the party. but yes, it does indeed work – at least I know I’ve tried # in the past. What does the + do?

edit: in case anyone else was curious: MQTT Topics, Wildcards, & Best Practices - MQTT Essentials: Part 5

According to the MQTT spec V3.1.1…

4.7.1.2 Multi-level wildcard
The number sign (‘#’ U+0023) is a wildcard character that matches any number of levels within a topic. The multi-level wildcard represents the parent and any number of child levels. The multi-level wildcard character MUST be specified either on its own or following a topic level separator. In either case it MUST be the last character specified in the Topic Filter [MQTT-4.7.1-2].

Non normative comment
For example, if a Client subscribes to “sport/tennis/player1/#”, it would receive messages published using these topic names:
 “sport/tennis/player1”
 “sport/tennis/player1/ranking”
 “sport/tennis/player1/score/wimbledon”

Non normative comment
 “sport/#” also matches the singular “sport”, since # includes the parent level.
 “#” is valid and will receive every Application Message
 “sport/tennis/#” is valid
 “sport/tennis#” is not valid
 “sport/tennis/#/ranking” is not valid

4.7.1.3 Single level wildcard
The plus sign (‘+’ U+002B) is a wildcard character that matches only one topic level.
The single-level wildcard can be used at any level in the Topic Filter, including first and last levels. Where it is used it MUST occupy an entire level of the filter [MQTT-4.7.1-3]. It can be used at more than one level in the Topic Filter and can be used in conjunction with the multilevel wildcard.

Non normative comment
For example, “sport/tennis/+” matches “sport/tennis/player1” and “sport/tennis/player2”, but not “sport/tennis/player1/ranking”. Also, because the single-level wildcard matches only a single level, “sport/+” does not match “sport” but it does match “sport/”.

Non normative comment
 “+” is valid
 “+/tennis/#” is valid
 “sport+” is not valid
 “sport/+/player1” is valid
 “/finance” matches “+/+” and “/+”, but not “+”

2 Likes