Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the asciidoc in the repository:

Loading routes from XML files

Available as of Camel 2.6

This cookbook shows how to load and add routes from XML files into an existing CamelContext.

When adding routes as shown on this page, the routes is isolated and cannot re-use any existing onException, intercept etc.

You can define Camel routes in XML files using the <routes> tag with the namespace "".
Suppose we have the bar route as shown below in the barRoute.xml XML file.

Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'
<routes xmlns="">
    <!-- here we define the bar route -->
    <route id="bar">
        <from uri="direct:bar"/>
        <to uri="mock:bar"/>

    <!-- we could add more routes if we like,
         but in this example we stick to one route only -->

We can then load this route and add to the existing CamelContext using the following lines of code:

Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'
// load route from XML and add them to the existing camel context
InputStream is = getClass().getResourceAsStream("barRoute.xml");
RoutesDefinition routes = context.loadRoutesDefinition(is);

If you are using older versions of Camel, you can do this as well but it requires a bit more work. See this commit log.

© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram