简体   繁体   中英

Camel route multiple if condition

I have to write to multiple if condition in camel and I need help to go around.

if(token is NULL)
if(condition is NULL) 
if(Dates does not match)
Then execute this...

What I am trying is

.choice
.when(token is NULL)
.when(condition is NULL)
.when(Dates does not match)
.log(update DB)
.endchoice()

which dont work.. Please help

Two Conditions:

Predicate p1 = header("token").isEqualTo("001"):
Predicate p2 = header("condition").isEqualTo("002");

Combine these conditions:

Predicate cond = PredicateBuilder.and(p1, p2);

Then In Camel

.choice
.when(cond)
.log(update DB)
.endchoice()

The best way to do this is to use Predicates.

You can define Predicates as private field if you are using Java DSL, by using expression builder, to build multiple conditions, then use the predicate in your when(), your route would looks much cleaner and easier to read.

private static final Predicate invalidHeaders = or(header(XXX).isNull(), header(YYY).isNull());

.....

.when(invalidHeaders)

You need to do this in a single when and use and &&

.when(token is NULL && condition is NULL && XXX)

There are various ways to do this.

If you use Java code then you can append multiple predicates together: http://www.davsclaus.com/2009/02/apache-camel-and-using-compound.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM