Topic strings are the vocabulary of IBM MQ pub/sub. Every publication carries one; every subscription references one or a wildcard pattern. Unlike queue names that are flat identifiers, topic strings form a tree: each slash-separated segment is a level, parent paths encompass children for matching and authority, and wildcards let you subscribe to families of events without listing every leaf. Misunderstanding + versus # is the most common reason a new subscription “never receives anything”—the publish string retail/uk/store/order/created does not match retail/+/created because two levels sit where + allows only one. This tutorial explains hierarchy design, wildcard rules with worked examples, comparison of exact versus pattern subscriptions, naming standards for enterprises, interaction with TOPSTR on topic objects, and debugging DISPLAY SUB versus the publish string in logs.
Each segment between slashes is one level. Root-to-leaf depth can vary by branch—retail/uk/order/created is four levels; health/patient/admit is three. Deep hierarchies improve security granularity (grant SUB on health/patient/#) but increase operational complexity. Shallow trees simplify matching but cram too much meaning into one level. A common pattern is domain/entity/action or domain/region/entity/event. Document whether empty segments or trailing slashes are forbidden—double slashes create ambiguous levels teams did not intend.
| Character | Matches | Does not match |
|---|---|---|
| + (plus) | Exactly one level at that position | Zero levels or two levels at that position |
| # (hash) | Zero or more trailing levels at end of pattern | Levels before the # prefix (must match exactly) |
| Literal text | Exact segment spelling and case | Synonyms or typos |
| No wildcard | Full string exact match only | Child strings unless separate sub |
Published string: logistics/shipment/uk/dispatched. Subscription logistics/+/dispatched fails—uk is one level but shipment/uk is two levels between logistics and dispatched. Subscription logistics/shipment/+/dispatched succeeds—+ absorbs uk. Subscription logistics/# succeeds—# absorbs shipment/uk/dispatched. Subscription logistics/shipment/# also succeeds. Subscription logistics/+/+/dispatched succeeds with first + = shipment, second + = uk. Draw the tree on paper when designing patterns.
123456DEFINE SUB('SUB.UK.DISPATCHED') TOPICSTR('logistics/shipment/+/dispatched') + DEST('LOGISTICS.UK.Q') SUBUSER('logapp') DEFINE SUB('SUB.ALL.LOGISTICS') TOPICSTR('logistics/#') + DEST('LOGISTICS.ALL.Q') * Publish test: topic string logistics/shipment/uk/dispatched * First sub receives; second sub also receives
Subscriptions without wildcards must match the published string exactly (subject to case rules). Use exact subs when a service consumes one event type only—inventory/stock/adjustment. Use + when one level varies (country, tenant). Use # for monitoring or audit platforms that need wide coverage—treat # subscriptions as privileged because they see everything under a branch. Never grant SUB on # to general application IDs.
DEFINE TOPIC('FIN.PAYMENT') TOPSTR('finance/payment') anchors the branch. Publications may target the object or the string; subscriptions may reference TOPIC('FIN.PAYMENT') with wildcard suffix rules per IBM syntax. Renaming for applications can be done with ALIAS topic objects pointing at a new TOPSTR without republishing code strings—governance advantage over raw strings only.
setmqaut -t topic -n 'finance/payment/#' grants on a subtree. Publishing to finance/payment/completed requires PUB authority at or above that node. Planning strings therefore plans security boundaries—do not bury sensitive events under a wide branch with loose PUB grants.
A topic string is like country/city/street/event. Wildcard + means “any one city name.” Wildcard # means “everything below this street address line onward.” Wrong wildcard choice sends mail to the wrong district.
Topic strings are addresses with slashes between house, street, and town. Plus means “any one town.” Hash means “this town and everything inside it.”
For publish retail/eu/de/order/placed, which matches: retail/+/placed, retail/#, retail/+/order/placed?
Write a subscription that hears all retail order events in any country but not catalog events.
Document a naming standard table with three columns: level, meaning, example.
1. finance/payment/# matches:
2. retail/+/created matches retail/uk/created:
3. Slash in topic string separates:
4. Publisher string retail/uk/order must match subscription: