Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A brief introduction to responsive programming: how to master Reactor

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report