I'm trying to group several camel routes in different camel contexts to avoid component name clashing. I know how to configure several RouteBuilder classes in the same Context extending From CamelConfiguration this way
@Configuration
public class CamelConfig extends CamelConfiguration {
@Override
public List<RouteBuilder> routes() {
// here I create the RouteBuilder List and the return it
}
But how I can have some routes in one camel context and other routes in other camel context using Java Configuration?
You can add many Camel Routes defined in external XML files in just one Camel Context as the example bellow:
You can create your routes in a new xml file (ie. routes1-config.xml):
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<!-- this is an included XML file where we only the the routeContext -->
<routeContext id="routes1" xmlns="http://camel.apache.org/schema/spring">
<!-- we can have a route -->
<route id="cool">
<from uri="direct:start"/>
<to uri="mock:result"/>
</route>
<!-- and another route, you can have as many your like -->
<route id="bar">
<from uri="direct:bar"/>
<to uri="mock:bar"/>
</route>
</routeContext>
</beans>
and then import and reference it on the context inside the main camel xml file, like this:
<!-- import the routes from another XML file -->
<import resource="routes1-config.xml"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<!-- refer to a given route to be used -->
<routeContextRef ref="routes1"/>
<!-- we can of course still use routes inside camelContext -->
<route id="inside">
<from uri="direct:inside"/>
<to uri="mock:inside"/>
</route>
</camelContext>
For more details please check the official reference documentation from Apache Camel http://camel.apache.org/how-do-i-import-routes-from-other-xml-files.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With