As per the definition of Mono and Flux, both represent an asynchronous sequence of data, and nothing happens before you subscribe.
And there are two broad families of publishers: hot and cold. Mono and Flux generate data anew for each subscription. If no subscription is created, then data never gets generated.
And Hot publishers, on the other hand, do not depend on any number of subscribers.
Here is my code for the cold stream:
System.out.println("*********Calling coldStream************");
Flux<String> source = Flux.fromIterable(Arrays.asList("ram", "sam", "dam", "lam"))
.doOnNext(System.out::println)
.filter(s -> s.startsWith("l"))
.map(String::toUpperCase);
source.subscribe(d -> System.out.println("Subscriber 1: "+d));
source.subscribe(d -> System.out.println("Subscriber 2: "+d));
System.out.println("-------------------------------------");
and here is the output:
*********Calling composeStream************
ram
sam
dam
lam
Subscriber 1: LAM
ram
sam
dam
lam
Subscriber 2: LAM
-------------------------------------
How can i convert the above cold stream into the hot stream?