I am new to reactive programming. And try to understand how the sinks and flux works.
Following an instruction with code
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
public class SinkExample {
public static void main(String[] args) {
Sinks.Many<String> sink = Sinks.many().multicast().onBackpressureBuffer();
Flux<String> flux = sink.asFlux();
sink.tryEmitNext("Stock price updated!");
sink.tryEmitNext("Go checkout");
flux.subscribe(price -> System.out.println("Client 1 received: " + price));
flux.subscribe(price -> System.out.println("Client 2 received: " + price));
}
}
I should expect both my flux subscriber receives 2 events.
Client 1 received: Stock price updated!
Client 1 received: Go checkout
Client 2 received: Stock price updated!
Client 2 received: Go checkout
But when I run the program. I only get 1 subscriber(Client 1) receives the events
Client 1 received: Stock price updated!
Client 1 received: Go checkout
Does anyone know why?