我会创建一个动态路由生成器,例如
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); } }
并添加到某个事件,例如
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")); ..