camel系列-路由资源加载

在 CamelMain 加载

可以使用 camel.main.routes-include-pattern 配置项进行配置

  1. 配置清单
1
camel.main.routes-include-pattern=classpath:myroutes/*
  1. DSL 清单

可以同时将不同的 DSL 文件(包括 XML,YAML,java)放在 routes-include-pattern 指定的通配符目录下面,如下图

路由配置统一 xml dump

因为每个路由配置采用不同的 DSL 编写,查看时并不方便,所以系统提供了一个路由的 dump 配置,可以将所有的 dsl 配置转义成 xml 格式的 DSL 打印出来

  1. 路由 dump 配置清单
1
2
# dump routes as XML (routes are coded in different DSLs but can be dumped as XML)
camel.main.dump-routes = true
  1. 路由 dump 结果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<routes xmlns="http://camel.apache.org/schema/spring">

<route id="route1">
<from uri="timer:xml?period=5s"/>
<log id="log1" message="I am XML"/>
</route>

<route id="route2">
<from uri="timer://java?period=2000"/>
<setBody id="setBody1">
<method beanType="MyRouteBuilder" method="randomNumber"/>
</setBody>
<log id="log2" message="Random number ${body}"/>
</route>

<route id="route3">
<from uri="timer:yaml?period=3s"/>
<setBody id="setBody2">
<simple>Timer fired ${header.CamelTimerCounter} times</simple>
</setBody>
<to id="to1" uri="log:yaml?showBodyType=false&showExchangePattern=false"/>
</route>

</routes>

在 Spring Boot 中加载

与 CamelMain 类似,也是使用 routes-include-pattern 配置项指定加载目录,如下图

加载流程解析

  1. 初始化
  2. 监听文件变化
  3. 路由重加载

RoutesLoader 流程

调用堆栈信息