2.2. 蓝图 XML DSL 路由迁移
要将 Blueprint XML 路由定义从 Fuse 应用程序迁移到 CEQ,请使用 camel-quarkus-xml-io-dsl 扩展,并将 Fuse 应用程序路由定义直接复制到 CEQ 应用程序。然后,您需要将所需的依赖项添加到 CEQ pom.xml 文件中,并在 application.properties 文件中更新您的 CEQ 配置。
CEQ 支持 Camel 3,而 Fuse 7 支持 Camel 2。有关将 Red Hat Fuse 7 应用程序迁移到 CEQ 时升级 Camel 的更多信息,请参阅 从 Camel 2 迁移到 Camel 3。
有关在 Camel Quarkus 中使用 Bean 的更多信息,请参阅使用红帽构建的 Apache Camel for Quarkus 指南中的 CDI 和 Camel Bean 组件 部分。
2.2.1. xml-IO-DSL 限制 复制链接链接已复制到粘贴板!
您可以使用 camel-quarkus-xml-io-dsl 扩展来帮助将 Blueprint XML 路由定义迁移到 CEQ。
camel-quarkus-xml-io-dsl 扩展只支持以下 < camelContext& gt; 子元素:
- routeTemplates
- templatedRoutes
- rests
- Routes
- routeConfigurations
因为 Blueprint XML 支持 camel-quarkus-xml-io-dsl 扩展不支持的其他 bean 定义,您可能需要重写 Blueprint XML 路由定义中包含的其他 bean 定义。
您必须在单独的文件中定义每个元素(XML IO DSL)。例如,这是 Blueprint XML 路由定义的简化示例:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<restConfiguration contextPath="/camel" />
<rest path="/books">
<get uri="/">
<to ..../>
</get>
</rest>
<route>
<from ..../>
</route>
</camelContext>
</blueprint>
您可以使用以下文件中定义的 XML IO DSL 将此蓝图 XML 路由定义迁移到 CEQ:
src/main/resources/routes/camel-rests.xml
<rests xmlns="http://camel.apache.org/schema/spring">
<rest path="/books">
<get path="/">
<to ..../>
</get>
</rest>
</rests>
src/main/resources/routes/camel-routes.xml
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<from ..../>
</route>
</routes>
您必须使用 Java DSL 来定义不支持的其他元素,如 < restConfiguration>。例如,使用 camel-rests.xml 文件中定义的路由构建器,如下所示:
src/main/resources/routes/camel-rests.xml
import org.apache.camel.builder.RouteBuilder;
public class Routes extends RouteBuilder {
public void configure() {
restConfiguration()
.contextPath("/camel");
}
}
2.2.2. 蓝图 XML DSL 路由迁移示例 复制链接链接已复制到粘贴板!
{link
有关使用 XML IO DSL 扩展的更多信息,请参阅红帽构建的 Apache Camel for Quarkus 扩展中的 XML IO DSL 文档。
在本例中,您要将基于内容的路由定义从 Fuse 应用程序迁移到新的 CEQ 应用程序,方法是将 Blueprint XML 路由定义复制到 CEQ 应用程序中名为 camel-routes.xml 的文件。
流程
使用
code.quarkus.redhat.com网站,为本例选择以下扩展:- camel-quarkus-xml-io-dsl
- camel-quarkus-file
- camel-quarkus-xpath
- 选择 Generate your application 来确认您的选择并显示包含您生成的项目的存档的下载链接。
- 选择 Download the ZIP 将带有生成的项目文件的存档保存到您的机器中。
- 提取存档的内容。
进入从上一步中提取生成的项目文件的目录:
$ cd <directory_name>-
在
src/main/resources/routes/目录中创建一个名为camel-routes.xml的文件。 将以下
blueprint-example.xml示例中的 <route> 元素和子元素复制到camel-routes.xml文件中:blueprint-example.xml
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <camelContext id="cbr-example-context" xmlns="http://camel.apache.org/schema/blueprint"> <route id="cbr-route"> <from id="_from1" uri="file:work/cbr/input"/> <log id="_log1" message="Receiving order ${file:name}"/> <choice id="_choice1"> <when id="_when1"> <xpath id="_xpath1">/order/customer/country = 'UK'</xpath> <log id="_log2" message="Sending order ${file:name} to the UK"/> <to id="_to1" uri="file:work/cbr/output/uk"/> </when> <when id="_when2"> <xpath id="_xpath2">/order/customer/country = 'US'</xpath> <log id="_log3" message="Sending order ${file:name} to the US"/> <to id="_to2" uri="file:work/cbr/output/us"/> </when> <otherwise id="_otherwise1"> <log id="_log4" message="Sending order ${file:name} to another country"/> <to id="_to3" uri="file:work/cbr/output/others"/> </otherwise> </choice> <log id="_log5" message="Done processing ${file:name}"/> </route> </camelContext> </blueprint>camel-routes.xml
<route id="cbr-route"> <from id="_from1" uri="file:work/cbr/input"/> <log id="_log1" message="Receiving order ${file:name}"/> <choice id="_choice1"> <when id="_when1"> <xpath id="_xpath1">/order/customer/country = 'UK'</xpath> <log id="_log2" message="Sending order ${file:name} to the UK"/> <to id="_to1" uri="file:work/cbr/output/uk"/> </when> <when id="_when2"> <xpath id="_xpath2">/order/customer/country = 'US'</xpath> <log id="_log3" message="Sending order ${file:name} to the US"/> <to id="_to2" uri="file:work/cbr/output/us"/> </when> <otherwise id="_otherwise1"> <log id="_log4" message="Sending order ${file:name} to another country"/> <to id="_to3" uri="file:work/cbr/output/others"/> </otherwise> </choice> <log id="_log5" message="Done processing ${file:name}"/> </route>修改
application.properties# Camel # camel.context.name = camel-quarkus-xml-io-dsl-example camel.main.routes-include-pattern = file:src/main/resources/routes/camel-routes.xml编译您的 CEQ 应用程序。
mvn clean compile quarkus:dev注意此命令编译项目,启动应用程序,并允许 Quarkus 工具监视工作区中的更改。项目中的任何修改都会自动在正在运行的应用程序中生效。