2.2. 蓝图 XML DSL 路由迁移


要将蓝图 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 的更多信息,请参阅 迁移 Apache Camel

有关在 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 定义,您可能需要重写蓝图 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>
Copy to Clipboard Toggle word wrap

您可以使用以下文件中定义的 XML IO DSL 将此 Blueprint 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>
Copy to Clipboard Toggle word wrap

src/main/resources/routes/camel-routes.xml

<routes xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from ..../>
    </route>
</routes>
Copy to Clipboard Toggle word wrap

您必须使用 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");
    }
}
Copy to Clipboard Toggle word wrap

2.2.2. 蓝图 XML DSL 路由迁移示例

注意

有关使用 XML IO DSL 扩展的更多信息,请参阅 Red Hat build of Apache Camel for Quarkus Extensions 中的 XML IO DSL 文档。

在本例中,您要将基于内容的路由定义从 Fuse 应用程序迁移到新的 CEQ 应用程序,方法是将 Blueprint XML 路由定义复制到 CEQ 应用程序中名为 camel-routes.xml 的文件。

流程

  1. 使用 code.quarkus.redhat.com 网站,为本例选择以下扩展:

    • camel-quarkus-xml-io-dsl
    • camel-quarkus-file
    • camel-quarkus-xpath
  2. 选择 Generate your application 来确认您的选择并显示包含您生成的项目的存档的下载链接。
  3. 选择 Download the ZIP 将生成的项目文件与生成的项目文件保存到机器中。
  4. 提取存档的内容。
  5. 进入从上一步中提取生成的项目文件的目录:

    $ cd <directory_name>
    Copy to Clipboard Toggle word wrap
  6. src/main/resources/routes/ 目录中创建一个名为 camel-routes.xml 的文件。
  7. 将以下 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>
    Copy to Clipboard Toggle word wrap

    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>
    Copy to Clipboard Toggle word wrap

  8. 修改 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
    Copy to Clipboard Toggle word wrap
  9. 编译您的 CEQ 应用程序。

    mvn clean compile quarkus:dev
    Copy to Clipboard Toggle word wrap
    注意

    此命令编译项目、启动应用程序,并允许 Quarkus 工具监视工作区中的更改。项目中的任何修改都会在运行的应用程序中自动生效。

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部