Tamil Difference Between Spring REST Template and Reactive WebClient | InterviewDOT

preview_player
Показать описание

Spring Framework 5 introduces WebClient, a component in the new Web Reactive framework that helps build reactive and non-blocking web applications.

Tamil Reactive Spring | Spring WebCient in Spring WebFlux | InterviewDOT

Difference Between Spring REST Template and Reactive WebClient

Why was Spring WebFlux created?

Part of the answer is the need for a non-blocking web stack to handle concurrency with a small number of threads and scale with fewer hardware resources. Servlet 3.1 did provide an API for non-blocking I/O. However, using it leads away from the rest of the Servlet API, where contracts are synchronous (Filter, Servlet) or blocking (getParameter, getPart). This was the motivation for a new common API to serve as a foundation across any non-blocking runtime. That is important because of servers (such as Netty) that are well-established in the async, non-blocking space.

The other part of the answer is functional programming. Much as the addition of annotations in Java 5 created opportunities (such as annotated REST controllers or unit tests), the addition of lambda expressions in Java 8 created opportunities for functional APIs in Java. This is a boon for non-blocking applications and continuation-style APIs (as popularized by CompletableFuture and ReactiveX) that allow declarative composition of asynchronous logic. At the programming-model level, Java 8 enabled Spring WebFlux to offer functional web endpoints alongside annotated controllers.

Define “Reactive”
We touched on “non-blocking” and “functional” but what does reactive mean?

The term, “reactive,” refers to programming models that are built around reacting to change — network components reacting to I/O events, UI controllers reacting to mouse events, and others. In that sense, non-blocking is reactive, because, instead of being blocked, we are now in the mode of reacting to notifications as operations complete or data becomes available.

There is also another important mechanism that we on the Spring team associate with “reactive” and that is non-blocking back pressure. In synchronous, imperative code, blocking calls serve as a natural form of back pressure that forces the caller to wait. In non-blocking code, it becomes important to control the rate of events so that a fast producer does not overwhelm its destination.

Reactive API
Reactive Streams plays an important role for interoperability. It is of interest to libraries and infrastructure components but less useful as an application API, because it is too low-level. Applications need a higher-level and richer, functional API to compose async logic — similar to the Java 8 Stream API but not only for collections. This is the role that reactive libraries play.

Reactor is the reactive library of choice for Spring WebFlux. It provides the Mono and Flux API types to work on data sequences of 0..1 (Mono) and 0..N (Flux) through a rich set of operators aligned with the ReactiveX vocabulary of operators. Reactor is a Reactive Streams library and, therefore, all of its operators support non-blocking back pressure. Reactor has a strong focus on server-side Java. It is developed in close collaboration with Spring.

WebFlux requires Reactor as a core dependency but it is interoperable with other reactive libraries via Reactive Streams. As a general rule, a WebFlux API accepts a plain Publisher as input, adapts it to a Reactor type internally, uses that, and returns either a Flux or a Mono as output. So, you can pass any Publisher as input and you can apply operations on the output, but you need to adapt the output for use with another reactive library. Whenever feasible (for example, annotated controllers), WebFlux adapts transparently to the use of RxJava or another reactive library.

Spring Reactive WebClient WebFlux Example
Рекомендации по теме
Комментарии
Автор

Great explanation with pic representation looking forward for a complete spring course from you

mayilesh
Автор

Hi sir. A great explanation on spring web flux. Thank you so much sir. If possible please make more videos on spring web flux sir. Keep up the great work 👍👌.

saiprakash
Автор

Nice explanation. Please add more videos sir.

Shiva-zyjq
Автор

Dear Bro,
Very useful, and your content quality is so good. Keep going.
I have two clarifications:
1. It seems spring-webflux achieved non blocking io like nodejs. is it right?
2. Is this feature available in Java language without spring

RajeshSriMuthu
Автор

Can you explain bout functional interface in java 8

Rpradeen
Автор

Bro good job! One doubt... Using web client the requests are placed as tasks in event queue.when it returns reponse then the free thread will process it. In such cases, will the tasks not occupies the same memory as the thread does? I understand we are not blocking threads but at the same time as we add more tasks exponentially in the queue, this will also impact the performance of the application isn't it? How are you perceiving this....

jeromejj
Автор

Hi sir. Can u please explain in english

priyankauchekar
Автор

Pls, can you make an English video, note all of us speak Indian

ahmedsaka