阿帕奇骆驼侦听器

Apache Camel listener

我创建了一个路由器 class 并在 @Configuration 中标记为 @Bean。我不太确定的一件事是骆驼多久会进行一次数据库调用以获得 select 结果?一旦我在数据库中有了新条目,camel 就会检索并处理它。

public class SQLRouteBuilderForNewUserProcessing extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        //files refer camel files endpoint
        //noop will not move or delete the files
        from("sql:" +
             "select id from users where status=" + Status.NEW.ordinal() +
             "?" +
             "consumer.onConsume=update users set status = " + Status.PROCESSING.ordinal()
             " where id = :#id")
            .bean(UserDataTranslator.class, "transformToUserData")
            .to("log:uk.co.infogen.users?level=INFO");
    }
}

默认情况下,sql 消费者每 500 毫秒对数据库进行一次池化。您可以使用 consumer.delay

进行配置
from("sql:select ... &consumer.delay=5000")
  .to(...)

the documentation of the sql component

consumer.delay 长 500 Camel 2.11:SQL 仅限消费者:每次轮询之间的延迟毫秒数。

来自 http://camel.apache.org/sql-component.html