Spring integration Message handler chain usage?

13,044

Solution 1

A chain is a convenience to simplify configuration when endpoints are connected by direct channels:

Instead of

<int:channel id="foo1"/>

<int:service-activator input-channel="foo1" output-channel="foo2" ref="s1" />

<int:channel id="foo2"/>

<int:service-activator input-channel="foo2" output-channel="foo3" ref="s2/>

<int:channel id="foo3"/>

<int:service-activator input-channel="foo3" output-channel="foo4" ref="s3" />

<int:channel id="foo4"/>

You can use

<int:channel id="foo1"/>

<int:chain input-channel="foo1" output-channel="foo4">    
    <int:service-activator ref="s1" />
    <int:service-activator ref="s2" />
    <int:service-activator ref="s3" />
</int:chain>

<int:channel id="foo4"/>

Please use the current documentation.

Solution 2

I would take a look at channel interceptors (http://static.springsource.org/spring-integration/docs/latest-ga/reference/htmlsingle/#channel-interceptors). These would allow you to do something prior to the message hitting your input channel, which I assume is channelOne. You could log a message or throw an exception, etc. depending on your use case.

<channel id="channelOne">
    <interceptors>
        <ref bean="yourValidatingInterceptor"/>
    </interceptors>
</channel>

<beans:bean id="yourValidatingInterceptor" class="com.yourcompany.YourValidatingInterceptor"/>

Solution 3

we use Message Handler Chain when a set of handlers needs to be connected in a linear fashion.

<int:chain input-channel="marketDataInputChannel"> 
    <int:splitter ref="marketDataSplitter"/> 
    <int:service-activator ref="marketFieldServiceActivator"/> 
    <int:aggregator ref="marketDataAggregator"/> 
    <int:service-activator ref="marketItemServiceActivator"/> 
</int:chain>

in the example above, the output data of channel splitter will be the input of service-activator, and the output of service-activator will be the input of aggregator ...
I hope that this explanation help you to understand the utility of <int:chain />

Share:
13,044
user1016403
Author by

user1016403

Updated on June 22, 2022

Comments