3 Ocak 2022 Pazartesi

SpringWebFlux Flux.merge

Örnek
Şöyle yaparız
public Flux<Incidence> findAllFlux() {
  Flux<Incidence> lstPre1 = WebClient.create("...").get().retrieve()
.bodyToFlux(Incidence.class);
  Flux<Incidence> lstPre2 = WebClient.create("...").get().retrieve()
.bodyToFlux(Incidence.class);
  Flux<Incidence> lstPro1 = WebClient.create("...").get().retrieve()
.bodyToFlux(Incidence.class);
  Flux<Incidence> lstPro2 = WebClient.create("...").get().retrieve()
.bodyToFlux(Incidence.class);
  return Flux.merge(lstPre1, lstPre2, lstPro1, lstPro2);
}

Flux.delaySequence

Giriş
delayElements metodundan farklı. Açıklaması şöyle. Yani initial delay olarak düşünülebilir.
With this operator, a source emitting at 10Hz with a delaySequence Duration of 1s will still emit at 10Hz, with an initial "hiccup" of 1s. On the other hand, delayElements(Duration) would end up emitting at 1Hz.
Örnek
Şöyle yaparız
@GetMapping("/incidenceFlux/{env}/{server}")
public Flux<Incidence> findAllFlux(@PathVariable String env, @PathVariable String server) {
  return Flux.just(new Incidence(...),
     new Incidence(...),
   new Incidence(...)
    )
    .delaySequence(Duration.ofSeconds(3));
}