I'm a bit confused about error handling in streams. How can I handle errors in a stream such that the publisher is not impacted and I can continue to get the next event in the stream. I've tried a few combinations with retry() & onError() but did not get the expected results.
RingBufferProcessor<Integer> processor = RingBufferProcessor.create();
Stream<Integer> intStream = Streams.wrap(processor);
intStream.map(i -> {
if (i == 5) throw new RuntimeException("We don't like this guy!!");
return i;})
.retry()
.consume(i -> LOG.info("Val => " + i), e -> LOG.info("Error => \n", e));
for (int i = 0; i < 10; i++) {
processor.onNext(i);
}
The above code produces an infinite loop of (0, 1, 2, 4, 0, 1, 2 ...)
Without the retry you get, (0, 1, 2, 3, 4) and the exception propagates to
consume's error handler.
How do I process the exception (lets say simply LOG the exception) and continue receiving events 5-10? What does onErrorResumeNext() do - is that to switch to a fallback publisher in my example above? Are these some usage examples for this in the test code?
Thanks,
Gesly