'Spring integration enrichHeaders
I have a header "BackOffTime". I need to update it, but using another header "failCount".
Like this:
Long backOff = Math.pow(2, headers.get("failCount"));
enricherSpec.headerExpression("BackOffTime", backOff, true);
But problem is, that method enrichHeaders() doesn't have lambda with (message, headers) ->
so I can't get value from "failCount" header.
Is there a way to do it like this?:
.enrichHeaders(enricherSpec -> {
Long backOff = Math.pow(2, headers.get("failCount"));
enricherSpec.headerExpression("BackOffTime", backOff, true);
})
I found one way to get header, but it only allows to get it, but not use it in any function:
enricherSpec.headerExpression("BackOffTime", "headers['failCount']", true);
Solution 1:[1]
Consider to do something like this:
.enrichHeaders(h -> h.headerFunction("BackOffTime", m -> Math.pow(2, m.getHeaders().get("failCount", Double.class)), true))
The top-level Consumer<HeaderEnricherSpec> lambda is called only once and only during configuration phase. What you need is a function call per message. Therefore it has to be an option on that HeaderEnricherSpec already. And in our case it is a headerFunction(). It also can be done with the headerExpression(), but I find the Java syntax more convenient for DSL.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Artem Bilan |
