osgiapache-cameldsljbossfusefabric8

Best way to load dynamically routes in Apache Camel


we have developped application based on Karaf and Apache Camel. While our application is entirely based on bundles ( OSGI ) we are also loading the Camel context ( and its' Route Contexts ) on startup, whcih would mean that we have defined some static routes.

My question is. Is there a way to dynamically LOAD routes while the application is running without the need to reread the Camel Context as this will reset/restart the already existing routes. The same would apply to already created routes, for example if we want to edit a route whcih already exist.

The whole idea is that we are planning to put the routes in a database and as such, the database will be edited by a GUI.

So what's the best approach to do this? I do not beleive that it is really the best approach to reload OSGI bundle/bundles in case of a route being added, editted etc...

More or less during operation of the application, Different endpoints + their related routes will be added, edited, removed.

Please advise.

Thanks, Tiho


Solution

  • I think a good approach is to group your routes into small contexts with just a few (or maybe even single) routes per context. Then you reload that small context without causing interruption in other routes.

    However, as you don't believe in that approach, you can easily add and remove routes with methods on the CamelContext. Create a route builder that constructs routes from your database and use addRoutes and removeRoute.