Content-Based Routing

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.

Routing Inputs Compared

Where to read routing criteria
SourceProsCons
MQMD.MsgType / FormatNo parse; very fastLimited expressiveness
MQ user propertiesFlexible; JMS friendlyProducers must cooperate
XML XPathRich queries on legacy XMLCPU; schema drift
JSON JSONPathNatural for APIsLarge payloads costly

Example Rules Table

text
1
2
3
4
5
RuleId | 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.

ESQL-Style Logic Concept

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.

Explainer: Sorting Mail by Country Stamp

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.

Schema Evolution

  • Add optional fields with defaults so old messages still match rules.
  • Version namespace or schemaVersion property in payload.
  • Route unknown schemaVersion to REVIEW queue for manual handling.
  • Coordinate with producers before deprecating fields rules depend on.

Security and Compliance

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.

Performance

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.

Testing

  1. One test message per rule branch asserting arrival queue.
  2. Boundary values: null region, unknown region, malformed XML.
  3. Load test with production-like message size distribution.
  4. Failover test: backout and redelivery does not double-settle.

Explain Like I'm Five: Content-Based Routing

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.

Practice Exercises

Exercise 1

Write five routing rules for a fictional order XML.

Exercise 2

Decide header-only versus body parse for one interface.

Exercise 3

Design DLQ alert when DEFAULT rule exceeds ten messages per hour.

Frequently Asked Questions

Frequently Asked Questions

Test Your Knowledge

Test Your Knowledge

1. Content-based routing uses:

  • Payload or properties
  • Only queue name
  • CPU serial
  • Fan speed

2. Header routing is often:

  • Faster than full parse
  • Slower always
  • Illegal
  • Only z/OS

3. No matching rule should go to:

  • Default or DLQ
  • Delete silently
  • Random queue
  • Null

4. CBR is a type of:

  • Message router
  • Channel agent
  • Listener
  • Buffer pool
Published
Read time21 min
AuthorMainframeMaster
Verified: Enterprise Integration Patterns