I have a function that works on a single element:
Mono<Foo> myFunction(String arg) {
// do shiz
return result;
}
Now, I am trying to reuse the above method to do the same, but for a list of args:
Mono<List<Foo>> myNewFunction(List<String> args) {
Flux.fromIterable(args)
.map(currentArg -> myFunction(currentArg))
.map(Mono::block)
.collectList();
}
But it always fails with the same error:
ava.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3
...
Error has been observed at the following site(s):
|_ checkpoint ⇢ Handler com.xxx.yyy.zzz.Controller#foo(InputRequest) [DispatcherHandler]
|_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ HTTP POST "/v1/my/end/point" [ExceptionHandlingWebHandler]
(A controller is calling the myNewFunction)
I have verified that myFunction works when I call it directly from the controller. But when I go through myNewFunction, it fails.
How do I debug this and fix this? I can't tell what the error is. Thanks
block? Instead of returningMono<List<Foo>>you could instead return aFlux<Foo>, I guess.ResponseEntity<Flux<Mono<Foo>>>, the actual reponse I see in Postman is"scanAvailable": trueflatMap? You could rewrite this asFlux.fromIterable(args).flatMap(this::myFunction)(depending on where both of your methods are). This should result inFlux<Foo>.