Content-based routing (CBR) is a specialized message router that looks inside the envelope—or at standardized labels on the envelope—to decide where the message goes next. A payment message with currency GBP routes to LONDON.SETTLEMENT.Q while USD routes to NEWYORK.SETTLEMENT.Q; the order entry system only publishes to PAYMENT.ROUTER.IN once. IBM MQ stores the bytes and guarantees delivery; your routing service interprets those bytes under transactional get and put rules. Beginners embed routing if-chains in every producer microservice, so when the EU adds a new country code, twelve teams redeploy. Central CBR on MQ consolidates rules but concentrates risk if testing is weak. This tutorial compares routing on MQMD fields versus user properties versus XML XPath versus JSONPath, rule table maintenance, versioning message schemas, error paths for unknown content, performance tuning, testing matrices per rule branch, and pairing CBR with transformation when the target system needs different formats per destination.
| Source | Pros | Cons |
|---|---|---|
| MQMD.MsgType / Format | No parse; very fast | Limited expressiveness |
| MQ user properties | Flexible; JMS friendly | Producers must cooperate |
| XML XPath | Rich queries on legacy XML | CPU; schema drift |
| JSON JSONPath | Natural for APIs | Large payloads costly |
12345RuleId | Condition | TargetQueue R001 | /order/@region='EU' | SETTLE.EU.Q R002 | /order/@region='US' | SETTLE.US.Q R003 | MsgType='HIGH_VALUE' | SETTLE.PRIORITY.Q DEFAULT| else | SETTLE.REVIEW.Q
Store rules in a database or config file loaded every N minutes for dynamic CBR. Version the table with effective dates so marketing campaigns add rules without Friday night code deploy. Unit test each rule with sample messages kept in Git as fixtures.
In integration middleware, IF statements evaluate parsed fields. Conceptually: IF Body.region = 'EU' THEN COPY TO 'SETTLE.EU.Q' ELSEIF ... The same logic in Java reads JSON tree after GET. Keep rules declarative where possible—business analysts maintain spreadsheet exported to CSV rather than developers hard-coding nested ifs.
Content-based routing is sorting mail by reading the country on the letter inside the envelope, not only by the mailbox slot where it was dropped off.
Routing logs must not print full card numbers. Mask PAN in traces. Ensure CBR cannot be tricked into routing crafted messages to high-privilege queues—validate schema and authenticate producers with CONNAUTH. CHLAUTH on input queue limits who can inject messages the router will trust.
Scale router consumers competing on ROUTER.IN. Partition input into REGION.UK.IN and REGION.US.IN if volume warrants—rules become simpler per queue. Cache XPath compiled expressions. Reject oversize messages at PUT time with MaxMsgLength instead of failing deep in router.
Content-based routing is when you open each letter, read whether it says birthday or sorry, and put it in the happy card pile or the apology card pile.
Write five routing rules for a fictional order XML.
Decide header-only versus body parse for one interface.
Design DLQ alert when DEFAULT rule exceeds ten messages per hour.
1. Content-based routing uses:
2. Header routing is often:
3. No matching rule should go to:
4. CBR is a type of: