Hi there,
I am trying to implement simple content based router using Spring integration and cannot figure out what should be the right way.
Case
On input channel I receive a simple XML message
Based on the age value i want to determine whether a passenger is infant, child or adult, and direct message to a corresponding channel, i.e. infantChannel, childChannel or adultChannel. I want to use XPath to define conditions of the content based filter, since it is XML message.HTML Code:<passenger> <name>John</name> <age>28</age> </passenger>
Apache Camel Solution
With Apache Camel it is rather straight forward
Spring Integration SolutionHTML Code:<route> <from uri="file:src/test/resources/message?noop=true"/> <choice> <when> <xpath>/passenger/age <= '1'</xpath> <log message="INFANT"/> </when> <when> <xpath>/passenger/age > '1' and /passenger/age <= '12'</xpath> <log message="CHILD"/> </when> <when> <xpath>/passenger/age > '12'</xpath> <log message="ADULT"/> </when> <otherwise> <log message="ERROR"/> </otherwise> </choice> </route>
Well... I wasn't able to figure out and run out of patience. That is why I am writing to this forum.
It was logical to use <xpath-router>, but based on the documentation the output channels are determined dynamically based on the result of the XPath expression.
What I am trying to do is the following
Based on the doc, the XPath expressions are evaluated as NODESET and converter to list of strings, where every value of this list represents a channel name to which this message will be sent. In my case this will be just a list of integers from <age> message element and this this is not what I want. I just have four channels I want the message to be sent to.HTML Code:<si-xml:xpath-router id="passengerRouter" input-channel="passengerChannel" resolution-required="true" > <si-xml:xpath-expression expression="/passenger/age"/> </si-xml:xpath-router>
So, my question is how to configure <xpath-router> to implement my case?
Thanks in advance.


Reply With Quote