20 Ağustos 2023 Pazar

SpringWebFlux Flux.zip metodu

Giriş
Açıklaması şöyle
The zip operator combines elements from two or more reactive streams into pairs, tuples, or other custom objects. It's useful when you need to process elements from multiple streams together.
Örnek
Şöyle yaparız
Flux<Integer> numbers = Flux.just(1, 2, 3);
Flux<String> letters = Flux.just("A", "B", "C");
Flux<String> combined = Flux.zip(numbers, letters, (number, letter) -> number + letter);
Örnek
Şöyle yaparız
Flux<String> endpoint1 = webClient.get()
  .uri("/endpoint1").retrieve().bodyToMono(String.class);
Flux<String> endpoint2 = webClient.get()
  .uri("/endpoint2").retrieve().bodyToMono(String.class);

Flux<String> result = Flux.zip(
  endpoint1, 
  endpoint2, 
  (res1, res2) -> res1 + " " + res2);

Hiç yorum yok:

Yorum Gönder