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

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

視頻解說:https://www.bilibili.com/video/av79468713/

FluxMonoTestCase.javajava

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.javareact

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分鐘視頻學習
api

相關文章
相關標籤/搜索