Preeti Paul
Preeti Paul

Reputation: 41

Camel - How to stop camel route using java dsl, when using TIMER component to pool database?

I am trying to stop camel route when there is no more data in the database to pool, but unable to stop.

from("timer://pollTheDatabase?delay=50s")
.routeId("db-pooling-route")
.to("mybatis:queryToSelectData?statementType=SelectOne")
    .choice()
        .when().simple("${in.header.CamelMyBatisResult} == ''").stop()
        .otherwise().to("direct:processing-data")
        .end()
    .end()
.end();

Upvotes: 1

Views: 1047

Answers (2)

Preeti Paul
Preeti Paul

Reputation: 41

I tried using control-bus and it worked.

from("timer://pollTheDatabase?delay=50s&synchronous=false")
.routeId("db-pooling-route")
.to("mybatis:queryToSelectData?statementType=SelectOne")
    .choice()
        .when().simple("${in.header.CamelMyBatisResult} == ''")
        .to("controlbus:route?async=true&routeId=db-pooling-route&action=stop")
.end()
.to("direct:processing-data");

Upvotes: 1

Claus Ibsen
Claus Ibsen

Reputation: 55525

stop() means stop routing the current message, not the route itself. To stop/start routes etc you can use the controlbus component.

https://camel.apache.org/components/latest/controlbus-component.html

And since you want to stop the route from itself, then set the option async=true on the controlbus endpoint.

Upvotes: 1

Related Questions