Search code examples
javarabbitmqspring-webfluxproject-reactorreactor

How can I make Mono Void get returned in another Mono Void?


Mono<Void> my_function(final String reviewObject){  
  return Mono.fromCallable(
            () -> {
              ReviewDto reviewDto = new ReviewDto();
              
              try {
                objectMapper.updateValue(reviewDto, reviewObject);
              } catch (JsonMappingException e) {
                      throw new InvalidPayloadException("Invalid payload");
              }
              return reviewDto;
            }).then();
}

when I call my_function it is not invoking (working), what should I do ??

Mono<Void> another_function(){
   my_function(reviewObject);
}

Solution

  • Mono<Void> another_function(){
       return my_function(reviewObject);
    }
    

    and let a consumer of your another_function() to decide what to do with that returned Mono<Void>!

    To be precise it is of course a subscribe() this or other way to that reactive Publisher: https://projectreactor.io/docs/core/release/reference/#_subscribe_method_examples