Reputation: 75
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?
Upvotes: 3
Views: 4036
Reputation: 780
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
Upvotes: 1
Reputation: 63
You can use NMR (Normalized Message Router), http://camel.apache.org/nmr.html and expose the routes in each of those projects camel configuration as NMR routes and then consume it through your unified Java method using nmr:routename.
Upvotes: 0
Reputation: 22279
one CamelConfiguration
class creates one CamelContext
. The solution is to have multiple such sub classes (or similar).
Upvotes: 0