Magic hidden Solace topic subscription wildcards
Hi everyone! Hopefully you know all about Solace's different subscription wildcards that consumer/subscriber applications can use to match multiple topics:
*wildcard is a single-level wildcard, and can be used with a prefix: e.g.
>wildcard is a multi-level wildcard, must occur at the very end of a topic subscription on it's own level, and will match 1-or-more topic levels: e.g.
This is all covered in the docs: https://docs.solace.com/PubSub-Basics/Wildcard-Charaters-Topic-Subs.htm
Now, if you're familiar at all with MQTT, you might think Solace's wildcards are similar to MQTT's
# wildcards respectively. Well, they are definitely similar. Except:
- In MQTT,
+cannot be used with a prefix. At least, not according to the spec. BUT Solace supports this, and it depends on your MQTT client whether it will block you subscribing to something like
- In MQTT,
#is the multi-level wildcard, but matches 0-or-more levels, which means that
hello/world/from/aaronin MQTT. This is not the case with the Solace
So over the years, I've been asked a bunch of times if there is some way in Solace for a single subscription to match
hello/world/from/aaron. Usually you have to subscribe to both
hello/>. (Barclays SmartSockets apps, I'm looking at you!). Well, it turns out there is a way to do this. When Solace added support for MQTT, they needed to add the new 0-or-more wildcard. And the way to use it in non-MQTT (i.e. in native SMF APIs) is buried in the documentation here: https://docs.solace.com/Open-APIs-Protocols/MQTT/MQTT-Topics.htm#MQTT. Specifically:
Instead of the MQTT "#" wildcard, the subscription must use the ASCII character 0x03.
This section of the docs are talking about subscription manager capabilities (On-Behalf-Of), but can also be used by regular clients. So, for example, I have some JCSMP code:
And this will have the same 0-or-more multi-level capabilities as the MQTT
Hope you like this "hack"..! No need to have two separate Solace subscriptions for 0-and-1-or-more levels. Enjoy!