October 2018
Intermediate to advanced
556 pages
15h 18m
English
When talking about reactive publishers, we may distinguish two types of publishers—hot and cold.
Cold publishers behave in such a way that, whenever a subscriber appears, all of the sequence data is generated for that subscriber. Also, with a cold publisher, no data would be generated without a subscriber. For example, the following code represents the behavior of a cold publisher:
Flux<String> coldPublisher = Flux.defer(() -> { log.info("Generating new items"); return Flux.just(UUID.randomUUID().toString());});log.info("No data was generated so far");coldPublisher.subscribe(e -> log.info("onNext: {}", e));coldPublisher.subscribe(e -> log.info("onNext: {}", e));log.info("Data was generated twice for two subscribers"