Error handling in Akka streams
It is a common mistake to develop applications assuming that there will be no unexpected issues. Akka provides a set of supervision strategies to deal with errors that happen in actors. Akka Streams is no different and provides a similar approach to deal with unexpected exceptions. For instance, these exceptions might occur when an element in the stream is not the expected type. In this recipe, we will see how to handle such errors.
Getting ready
We will use the same prerequisites as before. We will define a supervision strategy to handle certain types of error.
How to do it...
For this recipe, perform the following steps:
- Create a file named
HandlingErrorsApplication.scala
inside thecom.packt.chapter8
package. This object will create a stream with two custom supervision strategies: one for a particular flow and one for the whole stream. The content should look like this:
package com.packt.chapter8 import akka.actor.ActorSystem import akka...