Reactive programming is a programming paradigm that promotes an asynchronous, non-blocking, event-driven approach to data processing. Reactive programming involves modeling data and events as observable data streams and implementing data processing routines to react to the changes to those streams.
In the reactive style of programming, we make a request for the resource and start performing other things. When the data is available, we get the notification along with data in the form of a call back function. In the callback function, we handle the response as per application/user needs.
Spring webflux is a reactive-stack web framework that is fully non-blocking, supports Reactive Streams back pressure, and runs on such servers as Netty, Undertow, and Servlet 3.1+ containers. It was added in Spring 5.0.
Reactive systems have certain characteristics that make them ideal for low-latency, high-throughput workloads. Project Reactor and the Spring portfolio work together to enable developers to build enterprise-grade reactive systems that are responsive, resilient, elastic, and message-driven.
Spring Webflux uses 2 Publishers:
A Mono is a specialized Publisher that emits at most one item and then optionally terminates with an onComplete signal or an onError signal. In short, it returns 0 or 1 element.
Mono<String> mono = Mono.just("Phoenix");Mono<String> mono = Mono.empty();
A Flux is a standard Publisher representing an asynchronous sequence of 0 to N emitted items, optionally terminated by either a completion signal or an error. These three types of signals translate to calls to a downstream subscriber’s onNext, onComplete, or onError methods.
Flux<String> flux = Flux.just(1,2,3,4,5);
Flux<String> flux = Flux.fromArray(new String[]{"1","2","3"});//To subscribe call method
flux.subscribe();
#engineering #reactive-programming #spring-webflux #computer-science