【问题标题】:Spring integration Message handler chain usage?Spring集成消息处理链的用法?
【发布时间】:2012-11-21 00:46:10
【问题描述】:

我是 Spring 集成的新手。我的配置文件中配置了几个频道,如下所示。

<int:channel id="channelOne" />
<int:channel id="channelTwo" />
<int:channel id="channelThree" />

我可以在这种情况下使用 MessageHandlerChain (http://static.springsource.org/spring-integration/docs/2.0.0.RC1/reference/html/chain.html) 吗?

谢谢!

【问题讨论】:

  • 通常,您定义了 2 个通道,一个输入和输出通道。您能进一步解释一下您要做什么...
  • @tjg184,我有一个输入通道和一个输出通道,但在输入和输出通道之间还有一个通道 (channelTwo) 可以进行某种验证。我可以在这种情况下使用消息处理程序链吗

标签: java spring spring-integration


【解决方案1】:

当端点通过直接通道连接时,链可以方便地简化配置:

代替

<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"/>

你可以使用

<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"/>

请使用current documentation

【讨论】:

    【解决方案2】:

    当需要处理一组处理程序时,我们使用 消息处理程序链 以线性方式连接。

    <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>
    

    在上面的例子中,通道splitter的输出数据将作为输入 service-activator,service-activator 的输出将作为输入 聚合器 ...
    我希望这个解释能帮助你理解&lt;int:chain /&gt;

    的用处

    【讨论】:

    • 你没有为这个链定义输出通道...我在其他地方看到过这个并且相信它是合法的,但是你的“marketItemServiceActivator”的输出去哪里了?
    【解决方案3】:

    我会看看频道拦截器 (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"/>
    
    猜你喜欢
    • 2018-08-25
    • 2021-06-09
    • 2013-03-30
    • 2020-04-05
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多