【发布时间】:2018-06-12 13:26:29
【问题描述】:
我正在尝试使用 routeContext 在同一个 camelContext 中重用 Camel 路由,但我发现使用 onException、intercept、dataFormats 存在限制,正如 How do I import routes from other XML files 所述
另一种选择是使用许多 camelContext 和 vm-direct 端点在它们之间进行通信,但 Spring Boot 只能使用一个 camelContext。在这个替代方案中,我找到了这篇文章How to configure multiple Camel Contexts in the Spring Boot application。
是否有其他替代方案可以不受任何限制地共享路线?
与Multiple camel context not accepted in Spring Boot Came single configl xml model ?相关的问题
添加了更多信息:
我想在一条包含许多小路线的大路线中构建完整的处理工作流程,其中每条路线都有特定的任务要做。我更喜欢 XML DSL 而不是 Java,以便能够使用图形编辑器。
主要处理工作流程将自动生成(不可修改),然后开发团队只需实施具有特定任务的小路线。一个必要条件是我必须使用 Spring Boot。
第一次尝试:一个 Camel 上下文并通过 routeContext 导入路由。使用直接端点来通信路由。
文件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>
文件transformationIN_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>
文件transformationOUT_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>
看起来我们不能在 routeContext 中使用 dataFormats:
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}'...
第二次尝试:很多 CamelContext。使用 direct-vm 端点来通信路由。
文件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>
文件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>
文件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>
问题 Spring Bootk 不喜欢在其中运行多个骆驼上下文:/ * 路由 tranformationIN (appContextTranformationIn) 和 tranformationOUT (appContextTranformationOut) 将在一个 camelContext 中,但 Spring Boot 的问题相同。
【问题讨论】:
-
你真的需要将这些路由导入到某个路由类中吗?一旦他们通过 Spring/Camel 注册,您应该能够通过
.to(...)定向到他们或通过您的路线中定义的消费者接收(即direct,seda,...)。你能解释一下为什么需要导入路由吗?你甚至使用 XML 配置的路由还是直接通过 Java 配置的路由(推荐从几个 Camel 版本开始) -
感谢您的回复!!。我添加了更多信息。
标签: java spring spring-boot apache-camel