从哪个端点来, 到哪个端点去
// java dsl 方式定义
RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("sftp:localhost/folder/test.json") // 端点1:请求到sftp服务器, 获取文件test.json
.to("activemq:queue:cheese"); // 端点2:将文件发送到activemq的指定队列
}
};
xml dsl 方式定义
<route>
<from uri="ftp:myserver/folder"/> <!-- 端点1: 请求到sftp服务器, 获取文件test.json -->
<to uri="activemq:queue:cheese"/> <!-- 端点2: 将文件发送到activemq的指定队列 -->
</route>
每个route的临时上下文对象, 仅在此route使用, 如果要使用全局变量,可以使用CamelContext
exchange-pooling官网链接
全局上下文对象
camelcontext官网链接
// java dsl 方式定义
RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("direct:a") // 从route.id = a来
.to("direct:b"); // 到route.id = b去
}
};
RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("sftp:localhost/folder/test.json") // 请求到sftp服务器, 获取文件test.json
.to("activemq:queue:cheese"); // 将文件发送到activemq的指定队列
}
};
<!-- xml dsl 方式定义 -->
<route>
<from uri="direct:a"/> <!-- 从route.id = a来 -->
<to uri="direct:b"/> <!-- 到route.id = b去 -->
</route>
<route>
<from uri="sftp:localhost/folder/test.json"/> <!-- 请求到sftp服务器, 获取文件test.json -->
<to uri="activemq:queue:cheese"/> <!-- 将文件发送到activemq的指定队列 -->
</route>
# yaml dsl 方式定义
- route:
precondition: "'{{format}}' == 'xml'" # 前置条件, 当format == 'xml',才执行route
from:
uri: "direct:a"
steps:
- to: "direct:b"
yaml定义的格式在【camel-yaml-dsl/src/generated/resources/schema
/camelYamlDsl.json】
下面的例子使用到如下类 :
(1)- route org.apache.camel.model.RouteDefinition
(2)steps org.apache.camel.model.ProcessorDefinition
(3)- to org.apache.camel.model.ToDefinition
(4) - from org.apache.camel.model.FromDefinition
(5)- log org.apache.camel.model.LogDefinition
# 定时器 起始路由流程
- route:
id: "START_TIMER"
group: "test_group"
from: zookeeper-master:SPLITPACKAGE_TIMER:quartz://SPLITPACKAGE_TIMER?cron=0+0/10+*+*+*+?
steps:
# 记录日志
- log:
message: "定时器开始: ${date:now:yyyy-MM-dd HH:mm:ss}"
# 路由指向 route = INIT_BEAN
- to: direct:INIT_BEAN
# bean初始化填充数值
- route:
id: "INIT_BEAN"
group: "test_group"
from: direct:SPLITPACKAGE_1
steps:
# 往exchange中设置上下文变量值, key = code, value = SPLIT_PACKAGE
- setProperty:
name: "code"
constant: "SPLIT_PACKAGE"
- setProperty:
name: "bodyName"
constant: "mainBody"
# 执行1: 调用指定springbean"CommonBean"的方法setGlobalProperty()
- to: bean:commonBean?method=setGlobalProperty
# 执行2: 路由到下一个步骤
- to: direct:SEND_SFTP_REQUEST
- route:
id: "SEND_SFTP_REQUEST"
group: "test_group"
from: direct:INIT_BEAN
steps:
# 发送sftp请求, 上传文件
- to: sftp://fjfclass@localhost:8022/sftp/upload?password=RAW(Class@2013_9)&binary=true&fileName=${header.fileName}
- to: direct: END_ROUTE
- route:
id: "END_ROUTE"
group: "test_group"
from: direct:SEND_SFTP_REQUEST
steps:
- to: bean:logUtils?method=generateLog