Spring Reactor

Reading Time: 2 minutes

The Reactor, as stated by Spring itself, is a foundational framework for asynchronous applications on the JVM which on modest hardware, makes it possible to process over 15,000,000 events per second with the fastest non-blocking Dispatcher . As it sounds, the Reactor framework is based on the Reactor design pattern

Reactive programming promotes

1. Asynchronous

2. Non-blocking

3. Event-driven approach to data processing (event-driven architecture)

The term, “reactive,” refers to programming models that are built around reacting to change like 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.

Background

The origins of Reactive Programming can probably be traced to the 1970s or even earlier.

As a first step in the direction of reactive programming, Microsoft created the Reactive Extensions (Rx) library in the .NET ecosystem. Rx was ported to several languages and platforms, including JavaScript, Python, C++, Swift, and Java, of course, called RxJava

The fundamental idea of ReactiveX is that events are data and data are events.

In the JVM world, there are few implementations based on Reactive programming paradigm

Why Reactor?

Reactor is a fourth-generation reactive library, based on the Reactive Streams specification, for building non-blocking applications on the JVM

Features :

1. Asynchronous and Non-Blocking for I/O operations

2. Backpressure saving subscribers from drowning (using reactor netty server)

3. Error handling channels

4. handle a large volume of concurrent requests coming from a single or multiple clients.

5. Function style programming

6. reactive streams are push-based which improves performance

7. Simple to use API’s Mono (for [0|1] elements) and Flux (for [N] elements)

Reactor Pattern

1. Reactor

A Reactor runs in a separate thread, and its job is to react to IO events by dispatching the work to the appropriate handler. It’s like a telephone operator in a company who answers calls from clients and transfers the line to the appropriate contact.

2. Handlers

A Handler performs the actual work to be done with an I/O event, similar to the actual officer in the company the client wants to speak to.

A reactor responds to I/O events by dispatching the appropriate handler. Handlers perform non-blocking actions.

Conclusion:-

To achieve high throughput we have to use it.

for more update got to https://stackabuse.com/spring-reactor-tutorial/


Knoldus-blog-footer-image

Written by 

Hi Guys This is Jatin,Currently working in Knoldus as a java developer