apache camel 的 split 和 aggregate
来源:互联网 发布:算法和并行计算 编辑:程序博客网 时间:2024/05/05 20:39
split和aggregate,看图就明白了。
下面我用一个例子来说明,非常难得,你很难在网上找到apache camel这样的例子。
1、路由
1
from(
"jms:TOOL.TTT"
).bean(TttBean.
class
,
"start"
).split(body(List.
class
),
new
MyAggregationStrategy())
2
.bean(TttBean.
class
,
"processOneLi"
).end().split(body(List.
class
)).bean(TttBean.
class
,
"processOne"
).bean(TttBean.
class
,
"end"
);
01
public
class
TttBean {
02
03
public
void
start(Exchange exchange){
04
List<List<Integer>> ii =
new
ArrayList<List<Integer>>();
05
for
(
int
i =
0
;i<
2
;i++){
06
List<Integer> li =
new
ArrayList<Integer>();
07
for
(
int
j =
10
;j <
15
; j++){
08
li.add(j);
09
}
10
ii.add(li);
11
}
12
exchange.getIn().setBody(ii);
13
System.out.println(
"start...."
);
14
}
15
16
public
void
processOneLi(Exchange exchange){
17
18
System.out.println(
"CamelSplitIndex:"
+ exchange.getProperty(
"CamelSplitIndex"
,
int
.
class
));
19
System.out.println(
"CamelSplitSize:"
+ exchange.getProperty(
"CamelSplitSize"
,
int
.
class
));
20
System.out.println(
"CamelSplitComplete:"
+ exchange.getProperty(
"CamelSplitComplete"
,
boolean
.
class
));
21
List<Integer> li = exchange.getIn().getBody(List.
class
);
22
System.out.println(
"oneLi"
);
23
}
24
25
public
void
processOne(Exchange exchange){
26
System.out.println(
"CamelSplitIndex:"
+ exchange.getProperty(
"CamelSplitIndex"
,
int
.
class
));
27
System.out.println(
"CamelSplitSize:"
+ exchange.getProperty(
"CamelSplitSize"
,
int
.
class
));
28
System.out.println(
"CamelSplitComplete:"
+ exchange.getProperty(
"CamelSplitComplete"
,
boolean
.
class
));
29
30
int
i = exchange.getIn().getBody(
int
.
class
);
31
System.out.println(i);
32
}
33
34
35
public
void
end(Exchange exchange){
36
System.out.println(
"ending...."
);
37
}
38
}
01
public
class
MyAggregationStrategy
implements
AggregationStrategy{
02
03
@Override
04
public
Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
05
06
07
if
(oldExchange ==
null
) {
08
// the first time we aggregate we only have the new exchange,
09
// so we just return it
10
return
newExchange;
11
12
}
13
14
List<Integer> lio = oldExchange.getIn().getBody(List.
class
);
15
List<Integer> lin = newExchange.getIn().getBody(List.
class
);
16
17
for
(Integer i : lin){
18
lio.add(i);
19
}
20
21
oldExchange.getIn().setBody(lio);
22
return
oldExchange;
23
}
24
25
}
start....
CamelSplitIndex:0
CamelSplitSize:2
CamelSplitComplete:false
oneLi
CamelSplitIndex:1
CamelSplitSize:2
CamelSplitComplete:true
oneLi
CamelSplitIndex:0
CamelSplitSize:10
CamelSplitComplete:false
10
ending....
CamelSplitIndex:1
CamelSplitSize:10
CamelSplitComplete:false
11
ending....
CamelSplitIndex:2
CamelSplitSize:10
CamelSplitComplete:false
12
ending....
CamelSplitIndex:3
CamelSplitSize:10
CamelSplitComplete:false
13
ending....
CamelSplitIndex:4
CamelSplitSize:10
CamelSplitComplete:false
14
ending....
CamelSplitIndex:5
CamelSplitSize:10
CamelSplitComplete:false
10
ending....
CamelSplitIndex:6
CamelSplitSize:10
CamelSplitComplete:false
11
ending....
CamelSplitIndex:7
CamelSplitSize:10
CamelSplitComplete:false
12
ending....
CamelSplitIndex:8
CamelSplitSize:10
CamelSplitComplete:false
13
ending....
CamelSplitIndex:9
CamelSplitSize:10
CamelSplitComplete:true
14
ending....
- apache camel 的 split 和 aggregate
- Apache Camel分解(split)与聚合(aggregate)
- Apache Camel的aggregate简单示例
- Apache Camel的split使用示例
- Apache Camel中的recipientList和routingSlip的区别?
- Apache Camel异常事务的实例和分析 -- 总述
- Apache Camel异常事务的实例和分析 -- 多线程事务
- Apache Camel TypeConverter的使用
- Apache Camel
- Apache Camel
- Apache Camel的sample的简单示例
- 关于apache camel的消息转发效率
- Apache Camel的routingSlip简单示例
- Apache Camel的multicast简单示例
- Apache Camel配置SSL的rest
- Apache Camel配置SSL的CXF
- Apache Camel 的一个file组件问题
- 基于Apache Camel的EIP集成
- 约瑟夫环问题
- Opening multiple databases with SQLite
- 系统引导文件之 boot.ini
- PKU-2243 Knight Moves (单BFS、双BFS)
- 一篇关于ReadWriteLock不错的文章
- apache camel 的 split 和 aggregate
- android学习笔记---50_样式与主题,给控件使用样式,给应用使用主题
- 文件重命名并输出文件名列表
- apache camel 用来复制网站页面
- 建议在主机上禁用的函数(PHP)
- mysql解压版的安装
- JNI学习(1)
- 给自己的企业建立本地ubuntu-apt仓库源
- 如何为机器视觉选择合适的采集卡