Book Image

Spring Integration Essentials

By : CHANDAN K PANDEY
Book Image

Spring Integration Essentials

By: CHANDAN K PANDEY

Overview of this book

Table of Contents (18 chapters)
Spring Integration Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Filters


Message filters are Spring Integration components, which act as an interceptor and decide whether to pass on the message to the next channel/component or drop it. Unlike routers, which decide what should be the next channel for a message, filters only take a boolean decision—whether to pass or not. There are two ways to define a message filter in Spring Integration:

  • Write a simple Java class and designate its method that will take decisions whether to pass the message or not

  • Configure it as a message endpoint that delegates to an implementation of the MessageSelector interface

This can be configured either in XML or annotations can be used.

Using a Java class to act as a filter

Let's take an example of using a simple Java class as a filter—this is part of our example about feeds. As feeds come in, we try to validate whether the payload is empty or not—then only pass it on for further processing:

<int:filter 
  input-channel="fetchedFeedChannel" 
  output-channel="filteredFeedChannel...