根据条件路由到不同的通道

时间:2014-08-19 22:06:31

标签: spring-integration

我想根据属性的条件将消息路由到不同的通道。 让我们说我有得分属性。如果分数<100,那么它将进入&#34; perfectchannel&#34;否则它会进入&#34; normalchannel&#34;

我在哪里指定拼写表达式或条件

<si:router id="serviceRouter" input-channel="serviceRoutingChannel"
    expression="payload.score" default-output-channel="badchannel"
    resolution-required="false">
    <si:mapping value="100" channel="perfectchannel" />
    <si:mapping value="<100 ??" channel="normalchannel" />
</si:router>

感谢你的帮助。

1 个答案:

答案 0 :(得分:2)

我们就此问题有JIRA ticket,但尚未提出解决方案。

现在,您可以使用expression中的条件实现此行为,并为truefalse以及路由器的cascad提供映射:

<si:router id="serviceRouter" input-channel="serviceRoutingChannel"
    expression="payload.score == 100">
    <si:mapping value="true" channel="perfectChannel" />
    <si:mapping value="false" channel="nestedRouterChannel" />
</si:router>

<si:router input-channel="nestedRouterChannel"
    expression="payload.score lt 100">
    <si:mapping value="true" channel="normalChannel" />
    <si:mapping value="false" channel="badChannel" />
</si:router>

<强>更新

使用<recipient-list-router>的另一种选择:

<recipient-list-router id="serviceRouter" input-channel="serviceRoutingChannel">
    <recipient selector-expression="payload.score == 100" channel="perfectchannel"/>
    <recipient selector-expression="payload.score lt 100" channel="normalchannel"/>
    <recipient selector-expression="payload.score gt 100" channel="badchannel"/>
</recipient-list-router>