3.3. XML IO DSL
要在 XML 中配置 Camel 路由、剩余部分或模板,您必须在 classpath 中添加 Camel XML 解析器依赖项。自 Camel Quarkus 1.8.0 起,链接:https://docs.redhat.com/en/documentation/developing_applications_with_red_hat_build_of_apache_camel_for_quarkus/4.10/html-single/red_hat_build_of_apache_camel_for_quarkus_reference/ @extensions-xml-io-dsl[camel-quarkus-xml-io-dsl] 是最佳选择。
使用 Camel Main,您可以设置指向资源 XML 文件的位置的属性,如路由、REST DSL 和 Route 模板 :
camel.main.routes-include-pattern = routes/routes.xml, file:src/main/routes/rests.xml, file:src/main/rests/route-template.xml
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>
当将 XML 路由与 Bean 搭配使用时,有时需要引用类名称,用于实例 beanType=org.apache.SomeClass。在这种情况下,可能需要注册类以在原生模式中反映。如需更多信息 ,请参阅原生模式 部分。
不支持带有 < ;beans> 或带有 & 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>
路由模板
<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>