camel系列-路由命名

命名的优点在于易于理解,把定义的流程场景下,下面记录一下,camel 内部对 CamelContext 和 route 自动命名的实现

CamelContext 命名

内部使用 CamelContextNameStrategy 接口来实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Strategy for assigning name to a {@link org.apache.camel.CamelContext}.
*
* @see ManagementNameStrategy
*/
public interface CamelContextNameStrategy {

/**
* Gets the name
* <p/>
* The {@link #isFixedName()} determines if the name can be re-calculated such as when using a counter, or the name
* is always fixed.
*
* @return the name.
*/
String getName();

/**
* Gets the next calculated name, if this strategy is not using fixed names.
* <p/>
* The {@link #isFixedName()} determines if the name can be re-calculated such as when using a counter, or the name
* is always fixed.
*
* @return the next name
*/
String getNextName();

/**
* Whether the name will be fixed, or allow re-calculation such as by using an unique counter.
*
* @return <tt>true</tt> for fixed names, <tt>false</tt> for names which can re-calculated
*/
boolean isFixedName();
}

Route 命名

Route 的 xml 配置由 RoutesDefinition 定义,其继承自 NamedNode,当 routeId 没有手动被设置时,会由 NodeIdFactory 自动创建一个 routeId

自动命名示例