Akka stream map with retry

北城以北 提交于 2019-12-11 11:27:11

问题


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

  1. the number of retry attempts
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!