Get the App
SLTechnology News&Howtos  ›  Development  › 

A brief introduction to responsive programming: how to master Reactor

Shulou Source: shulou.com Published: 2022-06-03 00:44:48 09月19日 Update

This article mainly introduces "how to master Reactor in the introduction of responsive programming". In daily operation, I believe many people have doubts about how to master Reactor in the introduction of responsive programming. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to master Reactor in the introduction of responsive programming". Next, please follow the editor to study!

Introduction to Reactor

Reactor is a non-blocking API based on JVM, which is directly combined with API in JDK8, such as CompletableFuture,Stream and Duration.

It provides two very useful asynchronous sequences, API:Flux and Mono, and implements the Reactive Streams standard.

It can also be combined with reactor-netty as an underlying service for some asynchronous frameworks, such as WebFlux introduced in Spring MVC 5, which we are very familiar with.

We know that the underlying WebFlux uses reactor-netty, and reactor-netty references Reactor. So, if you introduce webFlux dependencies into POM:

Org.springframework.boot spring-boot-starter-webflux

Then the project will automatically introduce Reactor.

If you are not using Spring webflux, it doesn't matter, you can directly add the following dependencies to use Reactor:

The Development History of io.projectreactor reactor-corereactive programming

In the beginning, Microsoft created Reactive Extensions (Rx) library for the .NET platform. Then RxJava implements the Reactive of JVM platform.

Then the Reactive Streams standard emerged, which defines some of the specifications that the Java platform must meet. And has been integrated into the java.util.concurrent class in JDK9.

Four very important components that implement Reactive Streams are defined in Flow, namely Publisher,Subscriber,Subscription and Processor.

The difference between Iterable-Iterator and Publisher-Subscriber

Generally speaking, reactive is used as an extension of the observer pattern in object-oriented programming languages.

Let's take a look at the implementation of this observer pattern in detail, taking Publisher and Subscriber as examples:

Public static interface Publisher {public void subscribe (Subscriber

Tags: Methods processing programming parameters objects sequences events that is patterns profiles two examples learning hell platform useful observers problems support observation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple Shulou Information MySQL Linux