user3749274
user3749274

Reputation: 31

Routing to a different channels based on condition

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.

Upvotes: 2

Views: 5499

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121542

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>

Upvotes: 2

Related Questions