【问题标题】:Merge Flux result and return Flux合并 Flux 结果并返回 Flux
【发布时间】:2021-07-30 15:01:11
【问题描述】:

我有一个List<Event>,对于每个Event,我需要设置EventDocument。我从 api 得到Flux<EventDocument>。我需要将正确的EventDocument 映射到Event 并返回Flux<Event>。

获取EventDocument的API调用

private Flux<EventDocument> getDocuments(List<Long> eventIds) {
    String url = this.documentServiceUrl + "/events?eventId=" + eventIds;
    return getWebClient()
            .post()
            .uri(url)
            .body(eventIds, List.class)
            .retrieve()
            .bodyToFlux(EventDocument.class)
            .log()
            .onErrorResume(error -> Flux.empty());
}

如何将上面的结果映射到更正Event 并返回Flux&lt;Event&gt;?

【问题讨论】:

    标签: java spring-boot spring-webflux project-reactor


    【解决方案1】:
    Flux<EventDocument> eventDocuments = ...;
    Flux<Event> events = eventDocuments.map(mapToEventFunction);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-30
      • 2014-07-12
      • 1970-01-01
      • 2018-02-04
      • 2019-10-19
      • 2019-04-08
      • 2018-03-26
      • 1970-01-01
      相关资源
      最近更新 更多