9
Copyright © 2014 by Intertech, Inc.

Spring Integration Tutorial (Part 3) - Filters

Embed Size (px)

DESCRIPTION

In Part 3 of our Spring Integration tutorial series we take a look at another message endpoint - the filter. Filters sit between message channels. Filters allow, on the basis of a message's content or metadata (in the message header), a message to pass from one channel to the next or reject and discard the message from the system - that is, not allowing the rejected message into the next channel. The filter is a "yea or nay" component determining which messages flow through and which messages do not. In this third part of the tutorial series, you explore the types and configuration of filters provided by Spring Integration and how to create your own custom filter using a Spring Integration MessageSelector interface.

Citation preview

Page 1: Spring Integration Tutorial (Part 3) - Filters

Copyright © 2014 by Intertech, Inc.

Page 2: Spring Integration Tutorial (Part 3) - Filters

Copyright © 2014 by Intertech, Inc.

Page 3: Spring Integration Tutorial (Part 3) - Filters

Copyright © 2014 by Intertech, Inc.

Page 4: Spring Integration Tutorial (Part 3) - Filters

Copyright © 2014 by Intertech, Inc.

Page 5: Spring Integration Tutorial (Part 3) - Filters

Copyright © 2014 by Intertech, Inc.

<int:filter input-channel="inboundChannel" output-channel="outboundChannel"expression="payload.startsWith('Hello')" />

<int:filter input-channel="inboundChannel" output-channel="outboundChannel"discard-channel="relook-channel" expression="payload.startsWith('Hello')" />

Page 6: Spring Integration Tutorial (Part 3) - Filters

Copyright © 2014 by Intertech, Inc.

public class MySelector implements MessageSelector {

public boolean accept(Message<?> message) {if (message.getPayload() instanceof String

&& ((String) message.getPayload()).startsWith("Hello")) return true;

return false;}

}

Page 7: Spring Integration Tutorial (Part 3) - Filters

Copyright © 2014 by Intertech, Inc.

<int:filter input-channel="inboundChannel" output-channel="outboundChannel"ref="selector" />

<bean id="selector" class="com.intertech.MySelector" />

Page 8: Spring Integration Tutorial (Part 3) - Filters

Copyright © 2014 by Intertech, Inc.

Click here for associated labs and video

Page 9: Spring Integration Tutorial (Part 3) - Filters

Copyright © 2014 by Intertech, Inc.

http://bit.ly/1hyrViM