简体   繁体   English

如何使用多个 web 调用和有条件的信号完成 flatMapMany?

[英]How can I flatMapMany with multiple web calls and conditionally signal complete?

I need to write a method which does我需要编写一个方法

  • Gets a Location header form an endpoint从端点获取Location header
  • Generates a series of Some which each should retrieved from the Location fetched from the first endpoint.生成一系列Some ,每个都应该从从第一个端点获取的Location中检索。
  • Need to return a Flux<Some>需要返回一个Flux<Some>

Which looks like this.看起来像这样。

private WebClient client;

Flux<Some> getSome() {

    // Get the Location header from an endpoint
    client
            .post()
            .exchange()
            .map(r -> r.headers().header("Location"))

    // Now I need to keep invoking the Location endpoint for Some.class
    // And Some.class has an attribute for pending/completion status.

    // e.g.
    while (true)
        final Some some = client
            .get()
            .url(...) // the Location header value above
            .retrieve()
            .bodyToMono(Some.class)
            .block()
            ;
    }

}

How can I map the Mono<String> to a Flux<Some> while using the Some#status attribute for completion?如何在使用Some#status属性完成时将Mono<String>转换为Flux<Some>

    // should return Flux<Some>
    client
            .post()
            .exchange()
            .map(r -> r.headers().header("Location"))
            .flatMapMany(location -> {
                // invokes location while retrieved Some#status is not `completed`
                // @@?
            })
            ;

inside the flatMapMany , perform the call that retrieves the Location .flatMapMany中,执行检索Location的调用。 apply a repeat().takeUntil(loc -> loc.complete()) to it (still inside the flatMapMany lambda)对其应用repeat().takeUntil(loc -> loc.complete()) (仍在flatMapMany lambda 内)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Spring Reactor中,如何在FlatMap或flatMapMany中的Mono或FLux主体中包含多个语句? - How to include multiple statements in the body of flatMap or flatMapMany for Mono or FLux in Spring Reactor? 我们如何迭代和打印来自 Reactor Flux 或 Mono FlatMap 或 FlatMapMany 的值? - How can we iterate and print the values from Reactor Flux or Mono FlatMap or FlatMapMany? 如何在 spring webflux/webclient 中有条件地链接 webclient 调用 - How do I conditionally chain webclient calls in spring webflux/webclient 如何在Spring中使用JAXB调用多个Web服务? - How can I invoke multiple web services using JAXB in Spring? 我如何有条件地从 json 响应中隐藏某些属性 - How can i hide some attribute conditionally from json response Spring单例初始化完成后如何运行方法? - How can I run a method after the Spring singleton initialization is complete? Flux.then() 在完成信号之前运行 - Flux .then() running before complete signal 如何测试骆驼路由依次调用了不同的端点? - How can I test that a Camel route calls different endpoints in order? 如何跨同一个 web 应用程序的多个实例存储 session 信息? - How can i store session information across multiple instances of the same web application? 如何使用 Spring WebClient 进行非阻塞调用并在所有调用完成后发送 email? - How to use Spring WebClient to make non-blocking calls and send email after all calls complete?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM