you can simply call a few different APIs on the CamelContext to add routes…something like this
context.addRoutes(new MyDynamcRouteBuilder(context, "direct:foo", "mock:foo"));
....
private static final class MyDynamcRouteBuilder extends RouteBuilder {
private final String from;
private final String to;
private MyDynamcRouteBuilder(CamelContext context, String from, String to) {
super(context);
this.from = from;
this.to = to;
}
@Override
public void configure() throws Exception {
from(from).to(to);
}
}
see this unit test for the complete example…