I have a header witch is incremented during flow, than message goes to a loop, where I route it based on this header value. I cant find a way to config this router.
I found this question Routing to a different channels based on condition
but it uses payload instead of headers: <expression="payload.score == 100">
I tried using Java config like this:
public ExpressionEvaluatingRouter router() {
var router = new ExpressionEvaluatingRouter("payload.getHeaders().get(failCount) => 2");
router.setChannelMapping("true", "logFailedChannel");
router.setChannelMapping("false", "retryChannel");
return router;
}
But it fails as it can not parse this "payload.getHeaders().get(failCount) => 5"
I also tried using HeaderRouner, but it wasn't good for me, because I had to hardcode every option for my conditions like this:
router.setChannelMapping("1", "retryChannel");
router.setChannelMapping("2", "retryChannel");
router.setChannelMapping("3", "logFailedChannel");
router.setChannelMapping("4", "logFailedChannel");
etc.
Is there any other way to config router?
payload.getHeaders().get(failCount) => 2
There is no such method getHeaders()
(unless your payload has one). The root for evaluation is Message<?>
which has payload
and headers
properties.
Try headers.get('failCount') >= 2
.