Java – camel CBR and POJO attribute check

I have a camel route for the order instance:

from("direct:start")
    .choice()
        .when(order.getProduct() == Product.Widget)
            .to("direct:widgets")
        .when(order.getProduct() == Product.Fizz)
            .to("direct:fizzes")
        .otherwise()
            .to("direct:allOtherProducts");

Therefore, if a particular order is a widget's order, it needs to be routed to direct: widgets, etc

When () method, I kill everything What I have is not a legal camel DSL syntax, which is used to describe the task I want to complete

So I asked: what do I put in each (...) method to complete the routing type I'm looking for? Thank you in advance!

Solution

You should put order Put the value of getproduct () in the title and use it like this:

from("direct:start")
        .choice()
            .when(header("product").isEqualTo(Product.Widget))
                .to("direct:widgets")
            .when(header("product").isEqualTo(Product.Fizz))
                .to("direct:fizzes")
            .otherwise()
                .to("direct:allOtherProducts");

Edit:

You can use a process (that is, in DSL):

<route id="foo">
    <from uri="direct:start"/>
    <process ref="beanProcessor" />
    <choice>
        <when>
            ...
        </when>
        <when>
            ...
        </when>
        <otherwise>
            ...
        </otherwise>
    </choice>

Bean declaration:

<bean id="beanProcessor" class="MyProcessor" />

Class:

public class MyProcessorimplements Processor {

     @Override
     public void process(Exchange exchange) throws Exception {
         exchange.getIn().setHeader("headerName",yourOrderObject);
     }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>