Routing to a different channels based on condition

[亡魂溺海] 提交于 2019-12-24 09:05:40

问题


I would like to route the message to different channels based on the condition of the property. Let's say I have score property. If the score is <100 then it goes to "perfectchannel" else it goes to "normalchannel"

Where do I specify the spel expression or condition

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

Appreciate your help on this.


回答1:


We have a JIRA ticket on the matter, but haven't come up with the solution yet.

Right now you can achieve this behaviour with condition from the expression and providing mapping for true and false and with cascad of the routers:

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

UPDATE

Another option to use <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>


来源:https://stackoverflow.com/questions/25393767/routing-to-a-different-channels-based-on-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!