Search code examples
springapache-camelspring-dsl

Camel content based routing with header in spring DSL issue


I am trying camel for some routing with Spring DSL. I am not able to get the message to the destinations. I know i am missing something please help me to figure out the issue. I have set the headers in deviceMessageRouteIdentifier as below

    Message outMsg = exchange.getOut();
    outMsg.setHeader("device_template_id","11");
    outMsg.setHeader("view_id", "2");  

my camel route is here

  <camel:route>
    <camel:from uri="direct:devicemessageprocessor"/>
    <camel:bean ref="deviceMessageRouteIdentifier"/>
    <camel:to uri="seda:deviceRouting"/>
    </camel:route>
            <camel:route>
        <camel:from
            uri="seda:deviceRouting?concurrentConsumers=10&amp;blockWhenFull=true&amp;purgeWhenStopping=true" />
        <choice>
            <when>
                <header>$device_template_id = '11'</header>
                <to uri="direct:gen2Bridge" />
            </when>
            <when>
                <header>$view_id = '1'</header>
                <to uri="direct:prediction" />
            </when>
        </choice>
    </camel:route>

  <camel:route>
        <camel:from uri="direct:gen2Bridge"/>
        <camel:bean ref="gen2BridgeProcessor" />
  </camel:route>

I am able to reach in deviceMessageRouteIdentifier but not able to reach destination gen2BridgeProcessor

Thanks in advance


Solution

  • You should use the simple language as the predicate, and not header. header is just for lookup of a header value.

     <header>$device_template_id = '11'</header>
    

    should be

     <simple>${header.device_template_id} == '11'</simple>
    

    And the equals operator is ==. See the simple language for more details