我想知道是否有一种方法可以使Camel满足我的要求,如下所示:

“定期从某个源(例如文件)读取数据,对其进行一些处理,然后将其写入其他位置”

我想出了如何去做减去“定期”部分的所有内容。我知道如何使用Quartz或Timer触发路线。但是当我使用这些零件时,该零件已经被拿走,所以我不能再更改主体了。

有什么建议吗?

最佳答案

您可以使用计时器/石英启动它,然后使用content enricherpolling consumer

//using timer/pollEnrich to populate the body with the polling results
from("timer://foo?period=5000")
    .pollEnrich("file:inbox")
    .to("file:outbout");

//using time/polling consumer bean for more flexibility and multiple polling
from("timer://foo?period=5000")
    .bean(myPollingConsumerBean, "doIt");

public static class MyPollingConsumerBean {
...
    public void doIt() {
      while (true) {
        String msg = consumer.receiveBody("file:inbox", 3000, String.class);
        if (msg == null) {
            break;
        }
        producer.sendBody("file:outbox", msg);
      }
    }
}

07-27 13:45