Message Filter
Explanation
Section titled “Explanation”A component sometimes receives messages it has no interest in. The Message Filter addresses this problem. It is a small processing step placed in front of that component.
How it works
The filter reads the content of each incoming message and compares it with a set of criteria. If the message matches, the filter passes it on. If not, the filter discards it.
The filter has only one output channel. That makes it a special, very simple kind of router. A router sends messages onward to a destination. See Message Routing for the wider family. A channel is the path messages travel along. See Message Channel.
In common frameworks
- In Apache Camel, the filter uses a predicate. A predicate is a test that answers true or false. Only messages with a true result continue. Messages with a false result are not routed further.
- In Spring Integration, the filter decides whether to pass or drop a message. It can look at a header value or at the message content.
What happens to rejected messages
Spring Integration offers choices beyond a silent drop:
- Send rejected messages to a dedicated discard channel.
- Raise an error when a message is rejected.
Example
Section titled “Example”An order system publishes every order event to one channel. A shipping component only cares about orders marked “ready to ship”. A filter in front of shipping checks each event. Ready orders pass through. All other events are discarded, or sent to a discard channel for review. The shipping component never sees the other events.
Trade-offs
Section titled “Trade-offs”Discarding a message is a decision that is easy to forget. A message that fails the condition is gone unless the design routes it to a discard channel or raises an error. Silent dropping keeps the flow simple. A discard channel or an error makes rejections visible, at the cost of extra channels or error handling to manage.
Diagram source
flowchart LR A[Input channel] --> F{Message Filter: criteria match?} F -- yes --> B[Output channel] F -- no --> D[Discarded]Checks
Section titled “Checks”- Each filter in the design states the content criteria that decide whether a message passes.
- The design states what happens to messages that do not match: dropped, sent to a discard channel, or raised as an error.
- Each filter has a single output channel.
Related
Section titled “Related”- Message Routing
- Content-based Router
- Content Filter
- Message Channel
- Dead Letter Channel
- Invalid Message Channel
- Selective Consumer
- Pipes and Filters
Sources
Section titled “Sources”- Message Filter - Enterprise Integration Patterns — enterpriseintegrationpatterns.com, accessed 2026-11-09
- Filter :: Apache Camel — camel.apache.org, accessed 2026-11-09
- Filter :: Spring Integration — docs.spring.io, accessed 2026-11-09