use of org.apache.camel.k.cron.CronSourceLoaderInterceptor in project camel-k-runtime by apache.
the class Application method load.
@GET
@Path("/load")
@Produces(MediaType.TEXT_PLAIN)
public String load() throws Exception {
final String code = "" + "\n- from:" + "\n uri: \"timer:tick?period=1&delay=60000\"" + "\n steps:" + "\n - log: \"${body}\"";
final YamlRoutesBuilderLoader loader = new YamlRoutesBuilderLoader();
loader.setCamelContext(context);
loader.build();
final Runtime rt = new DelegatingRuntime(runtime) {
@Override
public void stop() throws Exception {
stopped.set(true);
}
};
final CronSourceLoaderInterceptor interceptor = new CronSourceLoaderInterceptor();
interceptor.setRuntime(rt);
interceptor.setOverridableComponents("timer");
final RouteBuilder builder = (RouteBuilder) loader.loadRoutesBuilder(ResourceHelper.fromBytes("my-cron.yaml", code.getBytes(StandardCharsets.UTF_8)));
builder.addLifecycleInterceptor(interceptor);
try {
context.addRoutes(builder);
} catch (Exception e) {
throw new RuntimeException(e);
}
return "" + context.getRoutesSize();
}
Aggregations