【发布时间】:2016-01-10 14:05:21
【问题描述】:
我一直在玩 Spring Integration (SI) DSL。我有一个定义了以下异步网关的 Rest 服务:
@MessagingGateway
public interface Provision {
@Async
@Gateway(requestChannel = "provision.input")
ListenableFuture<List<ResultDto>> provision(List<ItemsDto> stuff);
}
在逐行演练中,我有以下示例 IntegrationFlow。
@Bean
public IntegrationFlow provision() {
return f -> f
.split(ArrayList.class, List::toArray)
.channel(c -> c.executor(Executors.newCachedThreadPool()))
.<ItemsDto, String>route(ItemsDto::getType, m -> m
.subFlowMapping("IPTV", sf -> sf
.<ItemsDto, String>route(ItemsDto::getAction, m2 -> m2
.subFlowMapping("OPEN", sf2 -> sf2
.handle((p, h) -> iptvService.open((ItemsDto) p))))
)
)
.aggregate();
}
如您所见,我有几层路由。我需要把事情分解一下。我已经尝试了几件不起作用的事情(在这里我没有得到响应......线程不等待):
@Bean(name = "routerInput")
private MessageChannel routerInput() {
return MessageChannels.direct().get();
}
@Bean
public IntegrationFlow provision() {
return f -> f
.split(ArrayList.class, List::toArray)
.channel(c -> c.executor(Executors.newCachedThreadPool()))
.<ItemsDto, String>route(ItemsDto::getType, m ->
m.subFlowMapping("IPTV", sf -> sf.channel("routerInput"))
)
.aggregate();
}
@Bean
public IntegrationFlow action() {
return IntegrationFlows.from("routerInput")
.<ItemsDto, String>route(ItemsDto::getAction, m -> m
.subFlowMapping("OPEN", sf -> sf
.handle(p -> iptvService.open((ItemsDto) p.getPayload())))).get();
}
我显然在概念上遗漏了一些东西 :) 有人可以提供“如何以及为什么”的意见吗?
我有一个需要拆分的项目列表,按“类型”路由,然后按“动作”路由,最后聚合(包含处理程序的响应)。每个处理的项目需要并行处理。
提前致谢
更新: 根据 Artem 的建议,我删除了所有异步内容。我把它修剪到几乎没有......
@Bean(name = "routerInput")
private MessageChannel routerInput() {
return MessageChannels.direct().get();
}
@Bean
public IntegrationFlow provision() {
return f -> f
.split()
.<ItemDto, String>route(ItemDto::getType, m ->
m.subFlowMapping("IPTV", sf -> sf.channel("routerInput")))
.aggregate();
}
@Bean
public IntegrationFlow action() {
return IntegrationFlows.from("routerInput")
.<ItemDto, String>route(ItemDto::getAction, m -> m
.subFlowMapping("OPEN", sf -> sf
.handle((p, h) -> iptvService.open((ItemDto) p)))).get();
}
我让它通过改变来响应
.handle(p ->
到这里
.handle((p, h) ->
所以它至少会响应,但它不会聚合拆分的 3 个测试项目。输出由 1 项组成。我需要使用流收集吗?发布政策?这应该没问题吧?
【问题讨论】: