Camel 组件之 Timer
来源:互联网 发布:软件总体技术方案 编辑:程序博客网 时间:2024/04/26 19:50
http://www.xeclipse.com/?p=1053
Timer是常用的定时组件,下面简单讲解一下这个组件的基础用法。
作用:定时产生一条Message。
注意:这个组件仅仅能用作consumer,不能用作producer。简单地说,就是只能放在from()里面,不能放在to()里面。
Timer用法
1
timer:name[?options]
非常简单,需要一个名字,以及必要的参数:
Timer产生的Message,带着特定的Properties,这些Properties分别为:
同时Message也有一个Header:
Timer示例
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
import
org.apache.camel.CamelContext;
import
org.apache.camel.builder.RouteBuilder;
import
org.apache.camel.impl.DefaultCamelContext;
/**
* A Camel Router
*/
public
class
TimerRouteBuilder
extends
RouteBuilder {
/**
* A main() so we can easily run these routing rules in our IDE
*/
public
static
void
main(String... args)
throws
Exception {
CamelContext camelContext =
new
DefaultCamelContext();
camelContext.addRoutes(
new
TimerRouteBuilder());
camelContext.start();
Thread.sleep(
100000000
);
}
/**
* Lets configure the Camel routing rules using Java code...
*/
public
void
configure() {
from(
"timer://myTimer?period=2000"
).setBody()
.simple(
"Current time is ${header.firedTime}"
).to(
"log:out"
);
}
}
每隔2秒钟,产生一条Message,并将消息的内容设为Timer触发的时间:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[ main]
12
Feb
10
14
:
41
:
16
,
985
DefaultCamelContext INFO Apache Camel
2.8
.
0
(CamelContext: camel-
1
) is starting
[ main]
12
Feb
10
14
:
41
:
16
,
985
DefaultCamelContext INFO JMX enabled. Using ManagedManagementStrategy.
[ main]
12
Feb
10
14
:
41
:
17
,
315
AnnotationTypeConverterLoader INFO Found
3
packages with
14
@Converter
classes to load
[ main]
12
Feb
10
14
:
41
:
17
,
355
DefaultTypeConverter INFO Loaded
153
core type converters (total
153
type converters)
[ main]
12
Feb
10
14
:
41
:
17
,
375
AnnotationTypeConverterLoader INFO Loaded
4
@Converter
classes
[ main]
12
Feb
10
14
:
41
:
17
,
395
DefaultTypeConverter INFO Loaded additional
22
type converters (total
175
type converters) in
0.040
seconds
[ main]
12
Feb
10
14
:
41
:
17
,
805
DefaultCamelContext INFO Route: route1 started and consuming from: Endpoint[timer:
//myTimer?period=2000]
[ main]
12
Feb
10
14
:
41
:
17
,
805
DefaultCamelContext INFO Total
1
routes, of which
1
is started.
[ main]
12
Feb
10
14
:
41
:
17
,
805
DefaultCamelContext INFO Apache Camel
2.8
.
0
(CamelContext: camel-
1
) started in
0.820
seconds
[ myTimer]
12
Feb
10
14
:
41
:
17
,
846
out INFO Exchange[ExchangePattern:InOnly, BodyType:String, Body:Current time is Fri Feb
10
14
:
41
:
17
CST
2012
]
[ myTimer]
12
Feb
10
14
:
41
:
19
,
806
out INFO Exchange[ExchangePattern:InOnly, BodyType:String, Body:Current time is Fri Feb
10
14
:
41
:
19
CST
2012
]
[ myTimer]
12
Feb
10
14
:
41
:
21
,
807
out INFO Exchange[ExchangePattern:InOnly, BodyType:String, Body:Current time is Fri Feb
10
14
:
41
:
21
CST
2012
]
[ myTimer]
12
Feb
10
14
:
41
:
23
,
808
out INFO Exchange[ExchangePattern:InOnly, BodyType:String, Body:Current time is Fri Feb
10
14
:
41
:
23
CST
2012
]
[ myTimer]
12
Feb
10
14
:
41
:
25
,
809
out INFO Exchange[ExchangePattern:InOnly, BodyType:String, Body:Current time is Fri Feb
10
14
:
41
:
25
CST
2012
]
- Camel 组件之 Timer
- Apache Camel之FTP组件学习
- Camel查找组件方式
- Camel自定义组件示例
- Camel自定义组件示例
- Camel-Component组件总结
- camel File 组件使用
- camel自定义组件
- camel 路由跳转组件使用
- camel EIP 之Aggregator
- Camel之AsyncProcessor
- Camel之Quartz2
- Camel之ActiveMQ
- Camel In Action 第七章 理解camel组件
- C#2D游戏开发之timer组件
- 例子二:使用servicemix-camel组件
- 例子二:使用servicemix-camel组件
- Apache Camel 的一个file组件问题
- c# 托管资源和非托管资源
- 经典面试题(七)
- AS3 操作XML,增加、删除、修改、查找
- 七夕夜、离别,涵情经河岸
- 静态查找
- Camel 组件之 Timer
- Android线程间通信机制(Handler Looper )
- 游戏二: 随处移动的Ball
- 紫薇花开的季节(二)
- hdu Minimum Inversion Number(线段树求逆序数有关问题的一个小归纳)
- Oracle 正则表达式函数的使用
- WPF Cover Flow Tutorial : Part 2
- JS文件中变量命名防止重复
- installshield中执行批处理