1

I have a method in spring boot that makes multiple mono call that returns a type string. This method will eventually return the results of all the mono calls which are later transformed into a POJO object. Tried Mono.zip but this accepts only 8 tuples. Is there a better solution?

eg:

Mono<String> mono1 = <Web client call>
Mono<String> mono2 = <Web client call>
Mono<String> mono3 = <Web client call>
Mono<String> mono4 = <Web client call>
.
.
.
.
.
.
Mono<String> monoN = <Web client call>
João Dias
  • 16,277
  • 6
  • 33
  • 45

1 Answers1

2

There is a static method on Mono that allows you to do this with an arbitrary number of Monos:

public static <R> Mono<R> zip(Function<? super Object[],? extends R> combinator, Mono<?>... monos)

Reference documentation: https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html#zip-java.util.function.Function-reactor.core.publisher.Mono...-

In Kotlin we can use it as

Mono.zip({ it.size }, mono1, mono2)

In this case you would now have a Mono<Int>, but you can aggregate the objects as you see fit.

João Dias
  • 16,277
  • 6
  • 33
  • 45