0

unable to access headers in the value attribute of router using like below

<int:router input-channel="route_profile"  expression="#jsonPath(payload, '$.entity')">
        <int:mapping value="headers.userId" channel="toWeb_send"/>
        <int:mapping value="headers.otherId" channel="find_preferences"/>
    </int:router>

Any thing here I am doing wrong.

1 Answer 1

1

The expression is not what expected in that value attribute:

 <xsd:attribute name="value" type="xsd:string">
      <xsd:annotation>
          <xsd:documentation>
            A value of the evaluation token that will be mapped to a channel reference
            (e.g., mapping value='foo' channel='myChannel')
            </xsd:documentation>
        </xsd:annotation>
 </xsd:attribute>

This value is exactly what the mentioned top-level expression returns.

So, let's imaging your expression="#jsonPath(payload, '$.entity')" may return foo or bar, therefore the mapping must be like:

<int:mapping value="foo" channel="toWeb_send"/>
<int:mapping value="bar" channel="find_preferences"/>

If there is some logic around those headers, they have to be included in the expression evaluation. Or you may choose some other way to calculate the routing key.

Sign up to request clarification or add additional context in comments.

1 Comment

I think in this scenarios I have to use recipientlist router docs.spring.io/spring-integration/reference/html/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.