Reputation: 3162
I wonder if there is a way to make Camel do what I need which is as follows:
"Periodically read data from some source (let's say a file), do some processing on it and write it to some other place"
I figured out how to do all that minus the "periodically" part. I know how to trigger a route using Quartz or Timer. But when I use those the part is already taken so I can't change the body anymore.
Any advice?
Upvotes: 2
Views: 2086
Reputation: 55555
You can use scheduled route policy as well http://camel.apache.org/scheduledroutepolicy.html
Upvotes: 5
Reputation: 21015
you can kick it off with timer/quartz and then use either a content enricher or a polling 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);
}
}
}
Upvotes: 4