Wildcards
Wildcards let one subscription match many topics. They work on every ConnectMQ plan and are the reason a well-structured topic tree is so useful.
Single level: +
+ matches exactly one topic level, anywhere in the filter.
Filter acme/istanbul/+/line1/+/telemetry | |
|---|---|
acme/istanbul/assembly/line1/cnc-01/telemetry | Matches |
acme/istanbul/painting/line1/robot-02/telemetry | Matches |
acme/istanbul/assembly/line1/cnc-01/status | No: different last level |
acme/istanbul/assembly/line1/cell-a/cnc-01/telemetry | No: one level too many |
Multi level: #
# matches the current level and everything below it. It must be the last character of the filter.
Filter acme/istanbul/assembly/# | |
|---|---|
acme/istanbul/assembly/line1/cnc-01/telemetry | Matches |
acme/istanbul/assembly/line2/press-04/alarms | Matches |
acme/istanbul/assembly | Matches (the parent level itself) |
acme/izmir/assembly/line1/cnc-01/telemetry | No: different site |
Useful filters for an ISA-95 tree
| You want | Filter |
|---|---|
| Everything of one site | acme/istanbul/# |
| Everything of one line | acme/istanbul/assembly/line1/# |
| Telemetry of every machine | acme/+/+/+/+/telemetry |
| Status of every machine on one line | acme/istanbul/assembly/line1/+/status |
| Everything in your organization | # |
Rules
- Wildcards are only for subscribing; a publish to a topic containing
+or#is invalid. +and#must fill a whole level:line+/temportemp#are invalid.#does not match system topics that start with$, such as$SYS/...; subscribe to those explicitly.- A subscription to
#returns only your organization's topics, but it can still be a lot of traffic. Subscribe to the branches you need. - Each filter counts once towards your plan's subscriptions per client (limits), however many topics it matches. Prefer one wildcard to many single topics.
- On the public test broker, a wildcard in the first level (
#,+/…) is refused with 0x87 Not authorized; use your own prefix, for exampleconnectmq/demo/7f3a91/#.
Wildcards and access control
ACL rules use the same syntax. A subscription is allowed only if a rule's filter covers the whole requested filter: with an allow rule on acme/istanbul/#, a client may subscribe to acme/istanbul/assembly/# but not to acme/#. A refused subscription gets 0x87 Not authorized in the SUBACK.
Related
- Design your topics and ISA-95
- Shared subscriptions to spread a wildcard's messages over several workers