2

我想知道是否有办法让骆驼做我需要的事情,如下所示:

“定期从某个来源(比如说一个文件)读取数据,对其进行一些处理并将其写入其他地方”

我想出了如何做所有这些减去“定期”部分。我知道如何使用 Quartz 或 Timer 触发路由。但是当我使用这些时,部分已经被占用了,所以我不能再改变身体了。

有什么建议吗?

4

2 回答 2

5

您也可以使用预定路由策略 http://camel.apache.org/scheduledroutepolicy.html

于 2012-10-26T06:36:32.840 回答
4

您可以使用计时器/石英启动它,然后使用内容丰富器或轮询消费者

//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);
      }
    }
}
于 2012-10-26T02:49:36.263 回答