小编use*_*862的帖子

Spring Integration Java DSL - 聚合器的配置

我有一个非常简单的集成流程,其中RESTful请求使用发布 - 订阅通道转发给两个提供者.然后,将两个RESTful服务的结果聚合在一个阵列中.整合流程的草图如下所示:

@Bean
IntegrationFlow flow() throws Exception {
    return IntegrationFlows.from("inputChannel")
            .publishSubscribeChannel(s -> s.applySequence(true)
                .subscribe(f -> f
                        .handle(Http.outboundGateway("http://provider1.com/...")
                                .httpMethod(HttpMethod.GET)
                                .expectedResponseType(ItemDTO[].class))
                ).subscribe(f -> f
                        .handle(Http.outboundGateway("http://provider2.com/...")
                                .httpMethod(HttpMethod.GET)
                                .expectedResponseType(ItemDTO[].class)
                        )
                )
            )
            .aggregate()
            .get();
}
Run Code Online (Sandbox Code Playgroud)

但是,在运行我的代码时,结果数组包含仅由一个RESTful服务返回的项.我缺少任何配置步骤吗?

UPDATE

考虑到Artem的评论,以下版本对应于完整的解决方案.

@Bean
IntegrationFlow flow() throws Exception {
    return IntegrationFlows.from("inputChannel-scatter")
            .publishSubscribeChannel(s -> s.applySequence(true)
                .subscribe(f -> f
                        .handle(Http.outboundGateway("http://provider1.com/...")
                                .httpMethod(HttpMethod.GET)
                                .expectedResponseType(ItemDTO[].class))
                        .channel("inputChannel-gather"))
                .subscribe(f -> f
                        .handle(Http.outboundGateway("http://provider2.com/...")
                                .httpMethod(HttpMethod.GET)
                                .expectedResponseType(ItemDTO[].class))
                        .channel("inputChannel-gather")))
            .get();
}

@Bean
IntegrationFlow gatherFlow() {
    return IntegrationFlows.from("inputChannel-gather")
            .aggregate(a -> a.outputProcessor(g ->  new GenericMessage<ItemDTO[]>(
                        g.getMessages().stream()
                                .flatMap(m -> Arrays.stream((ItemDTO[]) m.getPayload()))
                                .collect(Collectors.toList()).toArray(new …
Run Code Online (Sandbox Code Playgroud)

java dsl spring-integration aggregator

5
推荐指数
1
解决办法
1522
查看次数

标签 统计

aggregator ×1

dsl ×1

java ×1

spring-integration ×1