Spring集成分散度收集用法

时间:2018-10-16 12:29:25

标签: spring-integration spring-integration-dsl

在我的用例中,我需要进行2个REST调用以获取基于departmentId的项目列表。我需要合并两个列表并进行处理。

我使用的是scatterGather模式,可以看到正在调用fetchRoles和fetchGroups,但是最后没有看到“ Aggregated List:”。有人可以帮我代码有什么问题吗

@Bean
public IntegrationFlow processDomainFileFlow() {
    return IntegrationFlows
            .from("receiverChannel")
            .scatterGather(scatterer -> scatterer
                            .applySequence(true)
                            .recipientFlow(fetchRoles())
                            .recipientFlow(fetchGroups()))
            .log(INFO, CATEGORY, m -> "Aggregated List: " + m.getPayload())
            .get();
}

@Bean
public IntegrationFlow fetchRoles() {
    return IntegrationFlows.from("fetch.roles")
            .handle(outboundGateway( someServiceUrl + "/{departmentId}/roles")
                    .uriVariable("departmentId", m -> m.getHeaders().get("departmentId"))
                    .httpMethod(HttpMethod.GET)
                    .expectedResponseType(Item[].class))
            .get();
}

@Bean
public IntegrationFlow fetchGroups() {
    return IntegrationFlows.from("fetch.groups")
            .handle(outboundGateway(someServiceUrl + "/{departmentId}/groups")
                    .uriVariable("departmentId", m -> m.getHeaders().get("departmentId"))
                    .httpMethod(HttpMethod.GET)
                    .expectedResponseType(Item[].class))
            .get();
}

1 个答案:

答案 0 :(得分:0)

就您在gatherer中使用默认关联策略而言,您缺少

/**
 * @param applySequence the applySequence.
 * @return the router spec.
 * @see AbstractMessageRouter#setApplySequence(boolean)
 */
public S applySequence(boolean applySequence) {
scatterer

使其填充标准序列详细信息标头,以让默认的相关逻辑根据提供的序列详细信息标头执行其工作:https://docs.spring.io/spring-integration/reference/html/messaging-routing-chapter.html#scatter-gather-functionality

相关问题