How to create Flux from collection of Monos in spring


I have a problem, I don't know how to create Flux from the collection of Monos in spring.

Mono<Integer> mono1 = Mono.just(1);
Mono<Integer> mono2 = Mono.just(2);
Flux<Integer> flux = ?

How to merge multiple monos to single flux ?

1 Answer

5 years ago by

By using concat() of Flux class, we can combin or merge multiple Mono data streams.

		Mono<Integer> mono1 = Mono.just(1);
		Mono<Integer> mono2 = Mono.just(2);
		Flux<Integer> flux = Flux.concat(mono1, mono2);

Or also use merge() of Flux to merge multiple monos

                Mono<Integer> mono1 = Mono.just(1);
		Mono<Integer> mono2 = Mono.just(2);
		Flux<Integer> flux = Flux.merge(mono1, mono2);
5 years ago by Anil