# Message Filter

**In short:** A Message Filter checks each message against a condition on its content. Matching messages move on and the rest are discarded, so a component avoids receiving messages it does not care about.

## 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

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

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.

A Message Filter passes matching messages to its single output channel and discards the rest.

```mermaid
flowchart LR
  A[Input channel] --> F{Message Filter: criteria match?}
  F -- yes --> B[Output channel]
  F -- no --> D[Discarded]
```

## 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

- [Message Routing](https://arc.fuet.ch/concepts/integration/message-routing.md)
- [Content-based Router](https://arc.fuet.ch/concepts/integration/content-based-router.md)
- [Content Filter](https://arc.fuet.ch/concepts/integration/content-filter.md)
- [Message Channel](https://arc.fuet.ch/concepts/integration/message-channel.md)
- [Dead Letter Channel](https://arc.fuet.ch/concepts/integration/dead-letter-channel.md)
- [Invalid Message Channel](https://arc.fuet.ch/concepts/integration/invalid-message-channel.md)
- [Selective Consumer](https://arc.fuet.ch/concepts/integration/selective-consumer.md)
- [Pipes and Filters](https://arc.fuet.ch/concepts/styles-patterns/pipes-and-filters.md)

## Sources

- [Message Filter - Enterprise Integration Patterns](https://www.enterpriseintegrationpatterns.com/patterns/messaging/Filter.html) — enterpriseintegrationpatterns.com, accessed 2026-11-09
- [Filter :: Apache Camel](https://camel.apache.org/components/4.22.x/eips/filter-eip.html) — camel.apache.org, accessed 2026-11-09
- [Filter :: Spring Integration](https://docs.spring.io/spring-integration/reference/filter.html) — docs.spring.io, accessed 2026-11-09
