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);
}
}
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));
}