13 Mayıs 2021 Perşembe

SpringWebFlux Flux.range metodu - Cold Publisher

Örnek
Şöyle yaparız
Flux<Integer> flux = Flux.range(0, 2)
  .map(i -> {
    return i;
  });

//create a runnable with flux subscription
Runnable r = () -> flux.subscribe(s -> {...});
Thread t1 = new Thread(r, "t1");
Thread t2 = new Thread(r, "t2");

t1.start();
t2.start();
Örnek 
Şöyle yaparız
Flux<Integer> flux = Flux.range(0, 2)
  .subscribeOn(Schedulers.boundedElastic())
  .map(i -> {
    System.out.println("First Thread : " + Thread.currentThread().getName());
    return i;
  }).
  subscribeOn(Schedulers.single())
    .map(i-> {
     System.out.println("Second Thread : " + Thread.currentThread().getName());
     return i;
  });

flux.subscribe();
Thread.sleep(1000);

Hiç yorum yok:

Yorum Gönder