在我的用例中,我需要进行 2 次 REST 调用来获取基于 DepartmentId 的项目列表。我需要合并 2 个列表并处理它们。
我正在使用 scatterGather 模式,我可以看到正在调用 fetchRoles 和 fetchGroups,但我没有看到"聚合列表:"打印在末尾。有人可以帮助我代码中有什么问题吗
@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();
}
只要您在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