Search code examples
playframeworkakkaakka-stream

Akka-Stream 2.6.0+ deprecated actor system setup


I used to setup my actor system in the Bindings like so:

  implicit val System: ActorSystem = ActorSystem()
  implicit val Mat: Materializer = ActorMaterializer(ActorMaterializerSettings.create(System).withSupervisionStrategy(Decider))

but in the new version ActorMaterializer.apply/.create/.withSupervisionStrategy are deprecated:

  @deprecated(
    "Use the system wide materializer or Materializer.apply(actorContext) with stream attributes or configuration settings to change defaults",
    "2.6.0")

  @deprecated(
    "Use the system wide materializer or Materializer.create(actorContext) with stream attributes or configuration settings to change defaults",
    "2.6.0")

  @deprecated("Use attribute 'ActorAttributes.supervisionStrategy' to change setting value", "2.6.0")

and I'm not sure what should be change in my 2 lines of System/Mat....


Solution

  • Materializer is easy, supervision strategy requires more changes.

    1. Supervision strategy. You need to provide decider as attribute of a stream, e.g.:

      Source...
      .via(flow)
      .toMat(sink)(Keep...)
      .withAttributes(ActorAttributes.supervisionStrategy(decider))
      
    2. Create materializer this way:

      implicit val Mat: Materializer = Materializer(System)