Book Image

Spring Integration Essentials

By : CHANDAN K PANDEY
Book Image

Spring Integration Essentials

By: CHANDAN K PANDEY

Overview of this book

This book is intended for developers who are either already involved with enterprise integration or planning to venture into the domain. Basic knowledge of Java and Spring is expected. For newer users, this book can be used to understand an integration scenario, what the challenges are, and how Spring Integration can be used to solve it. Prior experience of Spring Integration is not expected as this book will walk you through all the code examples.
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...