New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need an error handler method on Flux when processing a stream of elements #49
Comments
Hey Victor, I just read your blog post it was a very informative one, well done ! Let's speak about patterns. As you highlighted, error is a terminal event but there are a few ways to deal with that and it goes down to subscription lifecycle. First , The The role of the operators like retry() is to use the immutable parent reference and a given condition to 're-subscribe' (after cleaning up its own operator state) to the parent or a given fallback sequence if we look at onErrorReturn etc. An alternative to the flatMap solution is to disable that "restarting" behavior and make the sequence definitive and not replayable. The operators Flux.fromIterable(tickers)
.publish() // Turn source into hot Publisher
.autoConnect() // Instructs the hot Publisher to start when at least one `Subscriber` subscribes
.flatMap() //Business logic that might fail
.retry(3) //retry on any error up to 3 times
.consume(System.out::println) Error mid flow (inside onSubscribe/onNext) will call |
Consider also frequently failing (and latency impacting) business logic to be wrapped as Basically creating new |
Hi @smaldini, Thanks for your answer. I´m still struggling to understand the whole model involved here but I supposed that the Mono.fromCallable + flatmap is enough for the moment. |
Related to #73 |
related to #80 |
@smaldini I think this is more related to #89 than #80. The proposal in #80 is not to handle the errors but just to hide the try/catch in a utility function. What both me and @victor-ferrer are trying to do is handle an exception thrown within an operator before it calls Using a |
Considering close since Flux#handle and extra Hooks features |
HI, perhaps this is already available in the Flux API but I couldn´t find and I think that could be interesting. I´d like to have a way to handle discrete errors while processing a stream of elements.
For instance, see this code:
I need to write this bulky try {} catch{} block to handle single errors and continue processing the rest of the flux. The methods I have seen so far allow me to return a specific value or to restart processing the flux from the beginning.
See this Stackoverflow question:
http://stackoverflow.com/questions/36237230/how-to-handle-error-while-executing-flux-map
As "akarnokd" comments, errors are terminal signals but perhaps this new method would help people developing with Reactor.
Thanks!
Victor
The text was updated successfully, but these errors were encountered: