Reactor系列(十五)backpressure背压

Posted javaweibiancheng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Reactor系列(十五)backpressure背压相关的知识,希望对你有一定的参考价值。

#java#reactor#flux#backpressure#

背压

视频讲解 : https://www.bilibili.com/video/av81253248/

技术图片

FluxMonoTestCase.java
package com.example.reactor;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import reactor.core.publisher.Flux;

import java.time.Duration;
import java.util.List;

@Slf4j
public class FluxMonoTestCase extends BaseTestCase {
    @Test
    public void pressure() throws InterruptedException {
        Flux<Long> longFlux = Flux.interval(Duration.ofMillis(1));
        longFlux.subscribe(new Subscriber<Long>() {
            Subscription subscription;
            @Override
            public void onSubscribe(Subscription subscription) {
                this.subscription = subscription;
                subscription.request(Long.MAX_VALUE);
            }

            @Override
            public void onNext(Long aLong) {
                perform(3L);
                subscription.request(3);
                System.out.println("val:"+aLong);
            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onComplete() {

            }
        });
        Thread.sleep(1000);
    }
}

关注公众号,坚持每天3分钟视频学习

技术图片

以上是关于Reactor系列(十五)backpressure背压的主要内容,如果未能解决你的问题,请参考以下文章

WebFlux 响应式编程初体验

Reactor系列collect集合

Reactor系列subscribe订阅

Reactor系列collectMap集合

Reactor系列(十九)StepVerifier测试

Reactor系列(十四)buffer缓冲