Reactor系列(十五)backpressure背压

 约 4 分钟

java#reactor#flux#backpressure

背压

视频讲解 : https://www.bilibili.com/vide...

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分钟视频学习

阅读 256

推荐阅读
目录