#java##reactor##flux##error##exception#
Video Commentary: 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)-> { // error was encountered continue subscription IF (EX instanceof IOException) { log.error ( "EX: {}, Val: {}" , EX, Val); } the else { } }) .onErrorResume ((EX) -> { // error is encountered, the new Flux return to continue the subscription. 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)); }
No public concern, adhere to three minutes a day learning videos