Reactor系列(六)Exception异常系列(六)Exception异常

java##reactor##flux##error##exception

视频解说:https://www.bilibili.com/video/av79468713/

FluxMonoTestCase.java

package com.example.reactor;

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

import java.io.IOException;

@Slf4j
public class FluxMonoTestCase extends BaseTestCase {
    @Test
    public void error() {
        Flux.range(-2, 5)
                .map(val -> {
                    int i = val / val;
                    return val;
                })
                .onErrorContinue((ex, val) -> {  //遇到错误继续订阅
                    if (ex instanceof IOException) {
                        log.error("ex:{},val:{}", ex, val);
                    } else {
                    }

                })
                .onErrorResume((ex) -> {   //遇到错误,返回新的Flux。继续订阅
                    return Flux.range(-2, 5);
                })
                .subscribe(System.out::println);
    }
}

BaseTestCase.java

package com.example.reactor;

import java.util.Arrays;
import java.util.List;

public class BaseTestCase {
    protected static final List<Employee> list = Arrays.asList(
            new Employee(1, "Alex", 1000),
            new Employee(2, "Michael", 2000),
            new Employee(3, "Jack", 1500),
            new Employee(4, "Owen", 1500),
            new Employee(5, "Denny", 2000));
}

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

阅读 411

推荐阅读