Responsive programming in Springboot Application (1)

一、Preliminary Knowledge

  1. Functional Interface
  2. Lambda expression
  3. Stream API
    1. Intermediate operation
      1. filter:Used to filter elements in a stream
      2. map:One-to-one conversion
      3. flatMap:One-to-many conversion
      4. distinct、sorted、peek、limit、skip、takeWhile…
    2. Terminal operation
      1. collect:toList/toMap/groupingBy

二、Reactor Core

1、Reactive Stream

https://www.reactive-streams.org

Java’s Reactive Streams is a standardized API for asynchronously processing data streams, designed to support backpressure mechanisms to ensure that system resources are not over-consumed due to mismatches in the speeds of producers and consumers during asynchronous data processing. The main goal of Reactive Streams is to provide a compatible and unified API that allows different libraries and frameworks to work seamlessly together, especially when dealing with large-scale data streams.

For more information about the Backpressure mechanism, please visit the article: https://blog.youkuaiyun.com/Josh_scott/article/details/140398863

The Reactive Streams API is primarily composed of the following four core interfaces:

  1. Publisher:A publisher, the source that produces the data stream.

    // The Publisher interface has only one method, subscribe, which is used to subscribe to the data stream.
    public interface Publisher<T> {
         
         
        void subscribe(Subscriber<? super T> s);
    }
    
  2. Subscriber:A subscriber consumes the data stream at the terminal.

    public interface Subscriber<T> {
         
         
        // Called when a subscriber subscribes, passing a Subscription object.
        void onSubscribe(Subscription s);
        // Called when a new data item is produced.
        void onNext(T t);
        //  Called when an error occurs.
        void onError(Throwable t);
        // Called when the data stream ends.
        void onComplete();
    }
    
  3. Subscription:A subscription manages the relationship between the publisher and the subscriber, including operations for requesting and canceling data.

    public interface Subscription {
         
         
        // Requesting the number of data items.
        void request(long n);
        // Canceling the subscription.
        void cancel();
    }
    
  4. Processor<T, R>:A processor is both a publisher and a subscriber, used to process data within the data stream.

    // The Processor interface 
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值