[英]How can I flatMapMany with multiple web calls and conditionally signal complete?
I need to write a method which does我需要编写一个方法
Location
header form an endpoint从端点获取Location
headerSome
which each should retrieved from the Location
fetched from the first endpoint.生成一系列Some
,每个都应该从从第一个端点获取的Location
中检索。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.