问题
How can i retry if mapping/processing of an element in the stream fails?
I have tried setting the decider in materializer but it does not offer retry. It simply maps exception to Supervision stage.
Thanks
回答1:
Consider it as a tip rather than complete answer. I recently implement similar functionality with futures and mapAsync
. There is a library called retry for retrying futures with different strategies such as pause or back off. But this method have a problem that because akka streams use bounded buffers, if all futures that mapAsync is buffered are failing, your pipeline will stop processing.
Another approach to this problem is building a flow with feedback loop that pushes failed messages back to start. This is better solution since failed ones won't block your pipeline, however, I found that it is harder to implement backoff strategy this way.
回答2:
From akka-stream 2.4.4 you can use recoverWithRetries
(docs here).
This basically allows you to provide
- the number of retry attempts
- alternative source(s) to switch to depending on the occurred failure
It's available for both Source
and Flow
.
来源:https://stackoverflow.com/questions/35868862/akka-stream-map-with-retry