将 Fuse 7 应用程序迁移到红帽构建的 Apache Camel for Quarkus


Red Hat build of Apache Camel 4.10

将 Fuse 7 应用程序迁移到红帽构建的 Apache Camel for Quarkus

摘要

将 Fuse 7 应用程序迁移到红帽构建的 Apache Camel for Quarkus 提供了关于从 Red Hat Fuse 7 迁移到红帽构建的 Apache Camel for Quarkus 的信息。

前言

向红帽构建的 Apache Camel 文档提供反馈

要报告错误或改进文档,请登录您的红帽 JIRA 帐户并提交问题。如果您没有红帽 JIRA 帐户,系统会提示您创建一个帐户。

流程

  1. 点击以下链接 创建 ticket
  2. 在 Summary 中输入问题的简短描述。
  3. 提供有关描述中问题或功能增强的详细描述。包括一个 URL,以在文档中发生问题。
  4. 点 Submit 创建问题并将其路由到适当的文档团队。

1.1.1. fuse

红帽 Fuse 是基于 Apache Camel 和 Apache Karaf 等开源社区的灵活集成解决方案。红帽 Fuse 是一个轻量级、灵活的集成平台,可实现快速的内部云集成。

您可以使用三个不同的运行时运行红帽 Fuse:

  • Karaf 支持 OSGi 应用程序
  • Spring Boot
  • JBoss EAP (企业应用平台)

1.1.2. Red Hat build of Apache Camel for Quarkus

红帽构建的 Apache Camel for Quarkus 将 Apache Camel 的集成功能及其大量组件库引入 Quarkus 运行时。红帽构建的 Camel Quarkus 为许多 Camel 组件提供了 Quarkus 扩展。

Camel Quarkus 利用 Camel 3 中所做的很多性能改进,从而降低内存占用率,更依赖于反映,启动时间更快。

在 Red Hat build of Apache Camel for Quarkus 应用程序中,您可以使用 Java DSL 定义 Camel 路由,以便您可以将 Fuse 应用程序中使用的 Camel 路由迁移到 CEQ。

1.1.3. Camel on EAP

Karaf 遵循 OSGI 依赖项管理概念,EAP 遵循EE 规范,即受容器化应用采用的应用服务器。

容器已逐渐成为打包应用的主要方法。因此,管理应用程序的责任包括部署、扩展、集群和负载平衡,已使用 Kubernetes 从应用服务器过渡到容器编配。

虽然 EAP 继续在 Red Hat Openshift 上支持,但 EAP 服务器上不再支持 Camel 3。因此,如果您在 EAP 服务器上运行 Fuse 7 应用程序,您应该考虑将应用程序迁移到 Apache Camel for Spring Boot 的红帽构建或红帽构建的 Apache Camel for Quarkus,并考虑迁移过程的一个重新设计,或将应用程序部分从 monolith 迁移到微服务架构。

如果不使用 Openshift,RHEL 虚拟机在为 Spring Boot 和 Quarkus 部署应用程序时仍然是有效的方法,Quarkus 也受益于其原生编译功能。评估用于支持在此类平台上管理微服务架构的工具非常重要。

红帽通过 Ansible 使用 Red Hat Ansible 进行中间件集合提供此功能

1.2. 标准迁移路径

1.2.1. XML 路径

使用 Spring XML 或 Blueprint XML 编写的 Fuse 应用程序应迁移到基于 XML 的类别,并可以 Spring Boot 或 Quarkus 运行时为目标,且迁移步骤没有区别。

1.2.2. Java 路径

使用 Java DSL 编写的 Fuse 应用程序应迁移到基于 Java 的类别,并可以 Spring Boot 或 Quarkus 运行时为目标,且迁移步骤没有区别。

1.3. 架构更改

OpenShift 已取代 Fabric8 作为 Fuse 6 用户的运行时平台,也是 Fuse 应用迁移的建议目标。

在迁移应用程序时,您应该考虑以下架构更改:

  • 如果您的 Fuse 6 应用程序依赖于 Fabric8 服务发现,则应在 OpenShift 上运行 Camel 3 时使用 Kubernetes 服务发现。
  • 如果您的 Fuse 6 应用程序依赖于 OSGi 捆绑包配置,则应在 OpenShift 上运行 Camel 3 时使用 Kubernetes ConfigMap 和 Secret。
  • 如果您的应用程序使用基于文件的路由定义,在 OpenShift 上运行 Camel 3 时请考虑使用 AWS S3 技术。
  • 如果您的应用程序使用标准文件系统,则生成的 Spring Boot 或 Quarkus 应用程序应部署到标准 RHEL 虚拟机上,而不是 Openshift 平台。
  • 将 Inbound HTTPS 连接到处理 SSL 要求的 Openshift 路由器。
  • Hystrix 功能委派到 Service Mesh.

1.4. javax 到 jakarta 软件包命名空间更改

Java EE 移至 Eclipse Foundation 和 Jakarta EE 的建立,因为用于所有 EE API 的 Jakarta EE 9 软件包已改为 jakarta …​

文档中的代码片段已更新为使用 jakarta 输入命名空间,但您需要小心操作并查看您自己的应用程序。

注意

这个更改不会影响作为 Java SE 一部分的 javax 软件包。

将应用迁移到 EE 10 时,您需要:

  • 将任何导入语句或其他源代码使用来自 javax 软件包中的 EE API 类更新到 jakarta
  • 更改任何以 javax. 开头的 EE 指定的系统属性或其他配置属性,使其以 jakarta 开头。
  • 使用 META-INF/services/jakarta.[rest_of_name] 名称格式来识别使用实施 EE 接口或通过 java.util.ServiceLoader 机制引导的应用程序中的实施类。

1.4.1. 迁移工具

第 2 章 将 Camel 路由从 Fuse 7 迁移到 Camel

注意

您可以使用 Java DSL、XML IO DSL 或 YAML 在 Red Hat build of Apache Camel for Quarkus 应用程序中定义 Camel 路由。

2.1. Java DSL 路由迁移示例

要将 Java DSL 路由定义从 Fuse 应用程序迁移到 CEQ,您可以将现有路由定义直接复制到红帽构建的 Apache Camel for Quarkus 应用程序,并将必要的依赖项添加到 Apache Camel for Quarkus pom.xml 文件的红帽构建中。

在本例中,我们将一个基于内容的路由定义从 Fuse 7 应用迁移到一个新的 CEQ 应用,方法是将 Java DSL 路由复制到 CEQ 应用中名为 Routes.java 的文件。

流程

  1. 使用 code.quarkus.redhat.com 网站,选择本例所需的扩展:

    • camel-quarkus-file
    • camel-quarkus-xpath
  2. 进入从上一步中提取生成的项目文件的目录:

    $ cd <directory_name>
    Copy to Clipboard Toggle word wrap
  3. src/main/java/org/acme/ 子文件夹中创建名为 Routes.java 的文件。
  4. 将 Fuse 应用程序的路由定义添加到 Routes.java,如下例所示:

    package org.acme;
    
    import org.apache.camel.builder.RouteBuilder;
    
    public class Routes extends RouteBuilder {
    	// Add your Java DSL route definition here
        public void configure() {
    	    from("file:work/cbr/input")
                .log("Receiving order ${file:name}")
                .choice()
                    .when().xpath("//order/customer/country[text() = 'UK']")
                        .log("Sending order ${file:name} to the UK")
                        .to("file:work/cbr/output/uk")
                    .when().xpath("//order/customer/country[text() = 'US']")
                        .log("Sending order ${file:name} to the US")
                        .to("file:work/cbr/output/uk")
                    .otherwise()
                        .log("Sending order ${file:name} to another country")
                        .to("file:work/cbr/output/others");
        }
    
    }
    Copy to Clipboard Toggle word wrap
  5. 编译您的 CEQ 应用程序。

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

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

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 以确认您的选择,并使用包含您生成的项目的存档的下载链接显示 overlay 屏幕。
  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 工具监视工作区中的更改。项目中的任何修改都会在运行的应用程序中自动生效。

法律通告

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat
返回顶部