java Spring集成消息处理程序链的用法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13685169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring integration Message handler chain usage?
提问by user1016403
I am new to spring integration. i have few channels configured in my configuration file as below.
我是 Spring 集成的新手。我的配置文件中配置了几个频道,如下所示。
<int:channel id="channelOne" />
<int:channel id="channelTwo" />
<int:channel id="channelThree" />
can i use MessageHandlerChain ( http://static.springsource.org/spring-integration/docs/2.0.0.RC1/reference/html/chain.html) in this scenario?
我可以在这种情况下使用 MessageHandlerChain ( http://static.springsource.org/spring-integration/docs/2.0.0.RC1/reference/html/chain.html) 吗?
Thanks!
谢谢!
回答by Gary Russell
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.
请使用当前文档。
回答by tjg184
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.
我会看看通道拦截器(http://static.springsource.org/spring-integration/docs/latest-ga/reference/htmlsingle/#channel-interceptors)。这些将允许您在消息到达您的输入通道之前做一些事情,我假设它是 channelOne。您可以根据您的用例记录消息或抛出异常等。
<channel id="channelOne">
<interceptors>
<ref bean="yourValidatingInterceptor"/>
</interceptors>
</channel>
<beans:bean id="yourValidatingInterceptor" class="com.yourcompany.YourValidatingInterceptor"/>
回答by BERGUIGA Mohamed Amine
we use Message Handler Chainwhen 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 splitterwill 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 />
在上面的例子中,channel splitter的输出数据将是service-activator的输入,service-activator的输出将是aggregator的输入......
我希望这个解释能帮助你理解<int:chain />