Say you have some fluxes and monos
val people: Flux<Person> = repo.getPeople()
val peopleCount: Mono<Int> = people.count()
and from e.g. a WebFlux controller you return a Mono<Response>:
data class Response(
val people: List<People>,
val personCount: Int
)
Where is the appropriate place in an application to resolve the flux and the mono to a List and Int respectively? Do you just block() everything? Is there a way to get the framework to resolve everything?
EDIT: I guess my main confusion is all the tutorials I've seen the fields inside the response object are not in fact reactive, so it seems like I need to resolve everything before returning the object from the controller. If the response object looked like this it would make more sense to me
data class Response(
val people: Flux<People>,
val personCount: Mono<Int>
)
block
the publishers in the controller or services, because it will lead to an exception, because you are not reactive anymore. You can return a Mono or Flux from the controller methods just fine and have it resolved by the framework. The same applies for the error handling. If your Mono/ Flux contain errors, this will also be tackled for you. - thinkgruen