Publisher And Subscriber
In reactor, if a publisher doesn't have a subscriber, it would not run the code at all.
For example, the following code would not run:
Publisher<Integer> source = Flux.range(1, 10);
For it to run, we need to call a subscribe
method:
Flux.range(1, 10).subscribe(System.out::println);
[!note]
In here we cannot callsource.subscribe(...)
because that will go into the interface ofPublisher.subscribe()
which takes aSubscriber
. We useFlux.subscribe
which takes aConsumer