0

I want to filter according to header. If some of property is not null, send data from that property to different route.

from(SAVE_RECEIVED_IDS)
    .process(exchange -> {
        //here i set true for filters because there is faulty data
        exchange.getIn().setFault(true); //for PROCESS_FAULTY route
    
        //if filter catches, it should get and send this but it does not come here
        exchange.setProperty("faultyOnes","somearraylistOrData"); //for PROCESS_FAULTY route
    
        exchange.setProperty("other fields irrelevant to faulty","somearraylistOrData");//for route GO_NEXT_ROUTE
    })
    //here i neeed to filter if value is ture
    
    .filter(exchange -> exchange.getIn().isFault()) //it does not come here
        .to(PROCESS_FAULTY)
    .end() //end for filter
    
    .to(GO_NEXT_ROUTE) //if there is no faulty come here. if there is faulty, after send come here.
    .end() //end from()

or should i use choice and when?

.choice()
  .when(header("foo").isEqualTo("bar"))
    ...
  .when(header("foo").isEqualTo("chese"))
    ...
  .otherwise()
    ....
.end(),

like this? I use isFaulty but headers are better or properties? But where do i keep faulty data? Thanks for answers

hk6279
  • 1,881
  • 2
  • 22
  • 32
msadasjwd
  • 105
  • 10

1 Answers1

0

First, please be careful while setting message as faulty. This is primarily designed for irrecoverable errors which should trigger error recovery routines.

headers are better or properties? But where do i keep faulty data?

Take a look at Passing values between processors in apache camel, also go through the following answer from Claus on same thread. Most notably, properties are safely stored for the entire duration of the processing of the message in Camel. In contrast, headers are part of the message protocol, and may not be propagated during routing (quoted form Claus answer) - in short, properties are better suited especially if your message is also passing across protocols (http, jms etc). So use properties for storing faulty data.

Avnish
  • 1,241
  • 11
  • 19