简体   繁体   中英

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
  • Generates a series of Some which each should retrieved from the Location fetched from the first endpoint.
  • Need to return a 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?

    // 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 . apply a repeat().takeUntil(loc -> loc.complete()) to it (still inside the flatMapMany lambda)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM