3.3. XML IO DSL


要在 XML 中配置 Camel 路由、剩余部分或模板,您必须在 classpath 中添加 Camel XML 解析器依赖项。自 Camel Quarkus 1.8.0 起,链接:https://access.redhat.com/documentation/zh-cn/red_hat_build_of_apache_camel/4.0/html-single/red_hat_build_of_apache_camel_for_quarkus_reference/ @extensions-xml-io-dsl[camel-quarkus-xml-io-dsl] 是最佳选择。

使用 Camel Main,您可以设置指向资源 XML 文件的位置的属性,如路由、REST DSLRoute 模板

camel.main.routes-include-pattern = routes/routes.xml, file:src/main/routes/rests.xml, file:src/main/rests/route-template.xml
Copy to Clipboard Toggle word wrap
注意

path globbing like camel.main.routes-include-pattern = pre/routes.xml 目前无法在原生模式下工作。

Route

<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://camel.apache.org/schema/spring"
        xsi:schemaLocation="
            http://camel.apache.org/schema/spring
            http://camel.apache.org/schema/spring/camel-spring.xsd">

    <route id="xml-route">
        <from uri="timer:from-xml?period=1000"/>
        <log message="Hello XML!"/>
    </route>

</routes>
Copy to Clipboard Toggle word wrap

警告

当将 XML 路由与 Bean 搭配使用时,有时需要引用类名称,用于实例 beanType=org.apache.SomeClass。在这种情况下,可能需要注册类以在原生模式中反映。如需更多信息 ,请参阅原生模式 部分。

警告

不支持带有 &lt ;beans&gt; 或带有 & lt;blueprint& gt; 元素的蓝图 XML。

路由 XML 应该位于简化的版本中,如下所示:

REST DSL

<rests xmlns="http://camel.apache.org/schema/spring">
    <rest id="greeting" path="/greeting">
        <get path="/hello">
            <to uri="direct:greet"/>
        </get>
    </rest>
</rests>
Copy to Clipboard Toggle word wrap

路由模板

<routeTemplates xmlns="http://camel.apache.org/schema/spring">
    <routeTemplate id="myTemplate">
        <templateParameter name="name"/>
        <templateParameter name="greeting"/>
        <templateParameter name="myPeriod" defaultValue="3s"/>
        <route>
            <from uri="timer:{{name}}?period={{myPeriod}}"/>
            <setBody><simple>{{greeting}} ${body}</simple></setBody>
            <log message="${body}"/>
        </route>
    </routeTemplate>
</routeTemplates>
Copy to Clipboard Toggle word wrap

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat