Filter
Message filters are entrusted with the decision of whether to pass or drop a message received. In Java this is implemented as Boolean method in which if it is “true” message will be passed through and if it is “false” the message will be dropped.
In EAI, message filter can be pictorially represented as shown in Figure 22-22 below.
Figure 22-22. Filter
Listing 22-13 below shows both Java code and the corresponding Spring configuration for declaring a filter endpoint in your application.
Listing 22-13. Java and Spring configuration for filter declaration
1 2 3 4 5 6 7 8 9 10 11 |
package com.mybook.loyalty.filters; public interface BookingFilter { public boolean filterBooking(Booking booking){ //Do the booking filtering } } |
1 2 3 4 5 6 7 8 9 |
<bean id=”bookingFilter” class=”com.mybook.loyalty.filters.BookingFilter”/> <filter ref=”bookingFilter” method=”filterBooking” input-channel=”bookings” output-channel=”validBookings”/> |
The default behaviour of filter is to silently drop the message if nothing is explicitly specified. There are other alternatives as shown below:
- Upon message rejection throw exception as shown in Listing 22-14 below in Spring configuration file.
Listing 22-14. Throw exception when message is rejected (Spring configuration)
1 2 3 4 5 6 7 8 9 |
<filter ref=”bookingFilter” method=”filterBooking” input-channel=”bookings” output-channel=”validBookings” throw-exceptionon-rejection=”true”/> |
- Send rejected message to discard channel as shown in Listing 22-15 below in Spring configuration file. Doing so makes such filters 2-way router or a switch.
Listing 22-15. Rejected message routed to discard channel
1 2 3 4 5 6 7 8 9 |
<filter ref=”bookingFilter” method=”filterBooking” input-channel=”bookings” output-channel=”validBookings” discard-channel=”invalidBookings”/> |
Splitter
A single message is taken in as input and the endpoint makes it split as multiple messages and sends these messages as output.
In EAI, message splitter can be pictorially represented as shown in Figure 22-23 below.
Figure 22-23. Splitter
The splitting strategy should be specifically provided as separate method as shown in the Listing 22-16 below.
Listing 22-16. Splitter method in Java and corresponding Spring configuration
1 2 3 4 5 6 7 8 9 |
public class SampleSplitterClass{ public List<Items> splitMethod(HugeClass hugeObject){ return hugeObject.getItems(); } } |
1 2 3 |
<bean id=”sampleSplitter” class=”com.mybook.sample.splitter.SampleSplitterClass”/> <splitter ref=” sampleSplitter” …/> |
Page Visitors: 13117

Tomcy John

Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023
Hi,
Thanks for this blog and information sharing!
I have one question from Spring Integration. Just thought of checking with you.
I have SimplewebserviceOutBoundGateway. I need to send a document / attachment to the webservice. How will i achieve that?
This is my current gateway configuration:
Please let me know, if you can throw some light in this area.
Thanks in Advance!
Hi,
Thank you for your information sharing.
I have one doubt,could you please suggest me the correct frameworks to address that issue.
My requirement is I would like to get and process files using spring and camel.
Thanks,
Madhu