Archive for September, 2011

It’s pretty probable that once you have your camel project running you will need to load new rules on the fly.

Although camel does not support this from configuration, it can be easily achieved. Using camel support for annotations and Spring one could easily achieve this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Component
public class RouteDefinitionLoader {
 
	@Inject CamelContext context;
 
        //Consider using PropertiesLoader or new Environment from Spring 3.1
        final String ROUTES_URL ="file://home/app/routes";
 
	@Consumes(uri=ROUTES_URL)
	public void routeAdded(InputStream is){
		try {
			RoutesDefinition routesDefinition = context.loadRoutesDefinition(is);
			context.addRouteDefinitions(routesDefinition.getRoutes());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
 
}



Can you see how simple this is? Your new Spring bean will use camel annotation support to create a consumer on a given directory. Once you drop your routes there, all you have to do add them to the currently running Camel Context.


Piece of cake huh?