如何在骆驼中为to()方法编写计时器

时间:2020-10-31 17:30:00

标签: apache-camel spring-camel

在此路由中,我想在完成 direct:first direct:first仅执行一次之后,在每个间隔时间内执行 direct:second端点 strong>这就是为什么我用定时器repeatcount = 1编写from()方法的原因,所以有人可以帮助我如何解决此问题

from("timer:repeatcount=1").
.to("direct:first").  
 to("direct:second").
.setBody(simple("Hello from timer at ${header.firedTime}"))
.to("stream:out");

1 个答案:

答案 0 :(得分:0)

  1. 使用loopdelay模拟计时器工作
from("timer:repeatcount=1")
    .to("direct:first")
    .to("direct:second");

from("direct:second")
    .loopDoWhile(true)        // never ending loop, check loop component for more control
        .setBody(simple("Hello from timer at ${header.firedTime}"))
        .to("stream:out")
        .delay(1000)          // delay 1s, check delay component for more control
    .end();                   // end loop
  1. 使用controlBus启动计时器an inactive route