Search code examples
springblockingdtoreactive

Convert document objects to DTO spring reactive


I'm trying to convert a document object that is retrieved by the ReactiveCrudRepository as a Flux<Client> into Flux<ClientDto>

Now that I figure out a way to do this, I'm not sure if this is blocking or not:

public Mono<ServerResponse> findAll(final ServerRequest serverRequest) {
    final Flux<ClientDto> map = clientService.findAll().map(client -> modelMapper.map(client, ClientDto.class)) /*.delayElements(Duration.ofSeconds(10))*/;
    return ServerResponse.ok()
      .contentType(MediaType.TEXT_EVENT_STREAM)
      .body(map, ClientDto.class);
  }

I've tried adding the commented delayElements method and it seems it's sending them one by one, so non-blocking.

I think this is more of a nested question, but at the core I want to know how do I figure out if I do something blocking.

Thanks in advance!


Solution

  • You are blocking if you explicitly call to block method or if you are using a standard jdbc connector to connect to the database instead of a reactive one like reactiveMongo provided by Spring Data. In the snnipet you have posted, there isn't any blocking, but to be totally sure you should review the code of your clientService class and its nested calls (to a repository for example)