ImranRazaKhan
ImranRazaKhan

Reputation: 2297

continue behavior in camel route execution

I want to put continue behaviour in route, my route is like following

from("file:D:\\?fileName=abc.csv&noop=true").split().unmarshal().csv() 
.to("direct:insertToDb").end();

from("direct:insertToDb")
.to("direct:getDataId")
.to("direct:getDataParameters")
.to("direct:insertDataInDb");

from("direct:getDataId")
.to("sql:SELECT id FROM data WHERE name = :#name)
.choice()
.when(header("id").isGreaterThan(0) )
.setProperty("id", header("id"))
.otherwise()
.log("Error for")
.endChoice().end();

I want that if direct:getDataId dont find any record , my execution of route for current record from CSV get skip and program process next request. it would be equal to continue keyword.

How i can achieve this in Apache Camel route?

Upvotes: 3

Views: 2231

Answers (2)

Alexey Yakunin
Alexey Yakunin

Reputation: 1771

You can modify your routes like this:

from("file:D:\\?fileName=abc.csv&noop=true").split().unmarshal().csv() 
.to("sql:SELECT id FROM data WHERE name = :#name?outputHeader=id&outputType=SelectOne)
.choice().when(header("id").isGreaterThan(0))
    .to("direct:getDataParameters")
    .to("direct:insertDataInDb")
.end();

Upvotes: 1

fiw
fiw

Reputation: 756

Have you got a test for this? I suggest you try using CamelTestSupport because what you want is how camel will execute by default.

From Camel Split Docs:

  • stopOnException
  • default:false
  • description: Whether or not to stop continue processing immediately when an exception occurred. If disable, then Camel continue splitting and process the sub-messages regardless if one of them failed. You can deal with exceptions in the AggregationStrategy class where you have full control how to handle that.

Upvotes: 0

Related Questions