I\'m trying to remove some boilerplate from routes in Camel.
For example, let\'s consider the two routes, which are similar and most of their inner stuff could be ge
I would create a dynamic route builder e.g.
public class MyRouteBuilder extends RouteBuilder {
private String another;
private String letter;
public MyRouteBuilder(CamelContext context,String another, String letter) {
super(context);
this.another=another;
this.letter=letter;
}
@Override
public void configure() throws Exception {
super.configure();
from("restlet:/"+another+"?restletMethods=GET")
.to("first:run_"+letter)
.to("second:jump_"+letter)
.to("third:fly_"+letter);
}
}
and add it on some event e.g
public class ApplicationContextProvider implements ApplicationContextAware {
@Override
public void setApplicationContext(ApplicationContext context)
throws BeansException {
camelContext=(CamelContext)context.getBean("mainCamelContext");
camelContext.addRoutes(new MyRouteBuilder(camelContext, "another1","A"));
camelContext.addRoutes(new MyRouteBuilder(camelContext, "another2","B"));
..