I have existing Spring Boot application that uses Camel framework for getting data from different folders. All routes poll data in similar way:
from(fileUriWithCurrentDay(path, config.getParams())).routeId(ROUTE_ID)
where method defined as follows:
public static String fileUriWithCurrentDay(String path, Map<String, String> params) {
path = path.endsWith(SEPARATOR) ? path : path + SEPARATOR;
return "file:" + path + currentDayPath() + fileParams(params);
}
and returns something like depending on the day:
c:/test/data/2021/242?noop=true&idempotent=false&autoCreate=false&includeExt=xml&scheduler=spring&scheduler.cron = "0 0 13 ? * *"
The cron is set to start one time per day. When cron time is reached the route starts to perform its job and finishes it correctly. But on the next day it starts to poll the same folder, e.g. 242 but it should be 243.
So the problem is: from endpoint should be calculated dynamically at its start.
I've read about dynamic from: in Camel, but didn't find any information that such option is supported out of the box.
I've tried to use pollEnrich()
option using header that is calculated, but it seem doesn't support dynamic endpoints as returns next error:
org.apache.camel.ResolveEndpointFailedException Dynamic expressions with ${ } placeholders is not allowed. Use the fileName option to set the dynamic expression.
How from endpoint can be refreshed after route is started?
I also see 2 possible solutions but didn't know will it help:
- Restart routes for recalculating from endpoint uri.
- Restart whole Camel context. Currently all routes are marked as Spring
@Component
.