🎄 Happy Holidays! 🥳
Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.
Happy Holidays!
Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.
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:
- The
*
wildcard is a single-level wildcard, and can be used with a prefix: e.g.hello/wo*
- The
>
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.hello/>
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 +
and #
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 likehello/wo+
- In MQTT,
#
is the multi-level wildcard, but matches 0-or-more levels, which means thathello/#
will match:hello
,hello/world
andhello/world/from/aaron
in MQTT. This is not the case with the Solace>
wildcard.
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
, hello/world
, and hello/world/from/aaron
. Usually you have to subscribe to both hello
and 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:
session.addSubscription(JCSMPFactory.onlyInstance().createTopic("hello/\u0003"));
And this will have the same 0-or-more multi-level capabilities as the MQTT #
wildcard.
Hope you like this "hack"..! No need to have two separate Solace subscriptions for 0-and-1-or-more levels. Enjoy!
Comments
-
Hi @Aaron ,
Could you please clarify below understanding for below line :In MQTT, # is the multi-level wildcard, but matches 0-or-more levels, which means that hello/# will match: hello, hello/world and hello/world/from/aaron in MQTT. This is not the case with the Solace > wildcard.
Suppose
As per above Example from your post: My Subscription: hello/# will derived to below correct subscription in MQTT- hello
- hello/world
hello/world/from/aaron in MQTT
But In case of Solace, If I consider My subscription: hello/>hello (This will not work in Solace as > expect one or more than 1
- hello/world ( This is correct)
- hello/world/from/aaron ( This is also correct in Solace)
Could you please clarify above understanding is correct or not? If not , Please clarify it as I am newbie to Solace
0