I'm trying to reuse Camel routes within the same camelContext using routeContext but I see that there are limitations with the use of onException, intercept, dataFormats as it's stated at How do I import routes from other XML files
The other option is to use many camelContext and vm-direct endpoints for communication between them but there is a limitation of only one camelContext with Spring Boot. On this alternative I have found this article How to configure multiple Camel Contexts in the Spring Boot application.
Is there any other alternative to be able to share routes without having any limitations?
Question related to with Multiple camel context not accepted in Spring Boot Came single configl xml model ?
Added more info:
I want build a full processing workflow in one big route with many small routes where every route has a specific task to do. I prefer XML DSL instead of Java to be able to use the graphic editor.
The main processing workflow will be automatically generated (unmodifiable) and then a development team have to implement only the small routes with specifics tasks. One requisite is I must use Spring Boot.
First try: One Camel context and import routes by routeContext. Using direct endpoint to comunicate routes.
File mainWorkFlow.xml
<!-- Import routerContexts-->
<import resource="tranformationIN_route.xml"/>
<import resource="tranformationOUT_route.xml"/>
<camelContext id="mainWorkFlow">
<!-- refer to custom routes -->
<routeContextRef ref="tranformationIN"/>
<routeContextRef ref="tranformationOUT"/>
<route id="main">
<from id="_inRequest" uri="cxf:bean:exposedWS"/>
<to id="_validation" uri="inputData.xsd"/>
<!-- Call route in another context for transformation data received to a backend service data model -->
<to id="_toTransformationInRoute" uri="direct:appTransformationInRoute"/>
<!-- Call backend service -->
<to id="_wsBE" uri="cxf:bean:backendWS"/>
<!-- Call route in another context for transformation data from backend service response to exposed service data model -->
<to id="_toTransformationOutRoute" uri="direct:appTransformationOutRoute"/>
</route>
</camelContext>
File tranformationIN_route.xml
<routeContext ...>
<endpoint id="reqTrans" uri="dozer:...req_transformation.xml"/>
<!--
Declare dataFormats used by dozer
-->
<dataFormats>
<jaxb contextPath="some.package" id="someID"/>
</dataFormats>
<route id="tranformationIN">
<from uri="direct:appTransformationInRoute"/>
<to id="_to1" uri="ref:reqTrans"/>
</route>
</routeContext>
File tranformationOUT_route.xml
<routeContext ...>
<endpoint id="reqTrans" uri="dozer:...resp_transformation.xml"/>
<!--
Declare dataFormats used by dozer
-->
<dataFormats>
<jaxb contextPath="some.package" id="someID"/>
</dataFormats>
<route id="tranformationOUT">
<from uri="direct:appTransformationOutRoute"/>
<to id="_to1" uri="ref:respTrans"/>
</route>
</routeContext>
Look like we can't use dataFormats within routeContext:
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 6 in XML document from class path resource [spring/custom-routes.xml] is invalid;
nested exception is org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 22; cvc-complex-type.2.4.a: Se ha encontrado contenido no válido a partir del elemento 'dataFormats'.
Se esperaba uno de '{"http://camel.apache.org/schema/spring":route}'...
Second try: Many CamelContext. Using direct-vm endpoint to comunicate routes.
File mainWorkFlow.xml
<camelContext id="mainWorkFlow">
<route id="main">
<from id="_inRequest" uri="cxf:bean:exposedWS"/>
<to id="_validation" uri="inputData.xsd"/>
<!-- Call route in another context for transformation data received to a backend service data model -->
<to id="_toTransformationInRoute" uri="direct-vm:appTransformationInRoute"/>
<!-- Call backend service -->
<to id="_wsBE" uri="cxf:bean:backendWS"/>
<!-- Call route in another context for transformation data from backend service response to exposed service data model -->
<to id="_toTransformationOutRoute" uri="direct-vm:appTransformationOutRoute"/>
</route>
</camelContext>
File appContextTranformationIn_context.xml
<camelContext id="appContextTranformationIn">
<endpoint id="reqTrans" uri="dozer:...req_transformation.xml"/>
<!--
Data forman generated automatically by dozer
If necessary, here I could use dataFormat, onException and interceptor
-->
<dataFormats>
<jaxb contextPath="some.package" id="someID"/>
</dataFormats>
<!-- -->
<route id="tranformationIN">
<from uri="direct-vm:appTransformationInRoute"/>
<to id="_to1" uri="ref:reqTrans"/>
</route>
</camelContext>
File appContextTranformationOut_context.xml
<camelContext id="appContextTranformationOut">
<endpoint id="reqTrans" uri="dozer:...resp_transformation.xml"/>
<!--
Data forman generated automatically by dozer
If necessary, here I could use dataFormat, onException and interceptor
-->
<dataFormats>
<jaxb contextPath="some.package" id="someID"/>
</dataFormats>
<route id="tranformationOUT">
<from uri="direct-vm:appTransformationOutRoute"/>
<to id="_to1" uri="ref:respTrans"/>
</route>
</camelContext>
Problems Spring Bootk don't like more than one camelcontext running inside it :/ * Routes tranformationIN (appContextTranformationIn) and tranformationOUT (appContextTranformationOut) would be in one camelContext but the problem with Spring Boot it the same.
.to(...)
or receive via the consumer defined in your route (i.e.direct
,seda
, ...). Can you explain more why you need to import routes? Do you even use XML configured routes or routes configured via Java directly (recommended as of a couple of Camel versions) – Roman Vottner