Camel-当使用TIMER组件合并数据库时,如何使用java dsl停止骆驼路线?

时间:2020-04-20 09:08:35

标签: timer apache-camel mybatis

当数据库中没有更多数据要缓冲但无法停止时,我试图停止骆驼路线。

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();

2 个答案:

答案 0 :(得分:1)

stop()表示停止路由当前消息,而不是路由本身。要停止/启动路线等,您可以使用Controlbus组件。

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

并且由于您要停止路由本身,因此请在Controlbus端点上设置选项async=true

答案 1 :(得分:0)

我尝试使用控制总线,并且可以正常工作。

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");
相关问题