Message Filter
The selective filter — not to be confused with router (which always dispatches).
Problem
A team subscribes to a general channel (all invoices) but only cares about invoices above €10,000. How to avoid uselessly processing small invoices?
Forces
- Republishing a filtered channel costs broker throughput (read + write).
- Asking the producer to split adds upstream complexity.
- Filtering at the consumer is local but consumes subscriber CPU.
- Criteria evolve — €10,000 today, €5,000 tomorrow.
Solution
Insert a Message Filter between the source channel and the target channel (or directly inside the consumer). The filter inspects the payload (typically via an expression — JSONPath, XPath, Camel expression) and republishes only matching messages. Simple implementation, semantics known to all.
EDI implementation
In EDI, typical examples: filter INVOIC > €10k for accounting, filter ORDERS with regulated products (alcohol, pharma) for compliance, filter negative MDNs to partner support. Implementation: Camel route `.filter()`, Kafka Streams `.filter()`, Lambda filter function. Reuse the schema registry for typed parsing.
Anti-patterns
- Filter that modifies the message — that is no longer a filter, that is a translator.
- Cascade filters without drop-rate monitoring — silent and impossible to debug.
- Filter too costly (full XML parse) overloading the consumer.
Related patterns
- Content-Based Router — dispatch vs filter.
- Message Router — parent concept.
Sources
- Hohpe G., Woolf B. — EIP, Message Filter (p. 237). www.enterpriseintegrationpatterns.com/patterns/messaging/Filter.html