码迷,mamicode.com
首页 > 其他好文 > 详细

Reactor系列(十五)backpressure背压

时间:2019-12-30 14:25:42      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:class   end   sleep   next   owa   png   width   lib   thread   

#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背压

标签:class   end   sleep   next   owa   png   width   lib   thread   

原文地址:https://www.cnblogs.com/JavaWeiBianCheng/p/12119273.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!