【问题标题】:Akka-Stream 2.6.0+ deprecated actor system setupAkka-Stream 2.6.0+ 已弃用的演员系统设置
【发布时间】:2020-11-17 09:47:59
【问题描述】:

我曾经像这样在 Bindings 中设置我的演员系统:

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

但在新版本中 ActorMaterializer.apply/.create/.withSupervisionStrategy 已被弃用:

  @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")

我不确定我的 2 行 System/Mat.... 应该改变什么。

【问题讨论】:

    标签: playframework akka akka-stream


    【解决方案1】:

    Materializer 很简单,监管策略需要更多的变化。

    1. 监督策略。您需要提供decider 作为流的属性,例如:

      Source...
      .via(flow)
      .toMat(sink)(Keep...)
      .withAttributes(ActorAttributes.supervisionStrategy(decider))
      
    2. 以这种方式创建物化器:

      implicit val Mat: Materializer = Materializer(System)
      

    【讨论】:

      【解决方案2】:

      是的,它已被弃用,并在 documentation 中明确说明。

      您实际上应该做的只是创建ActorSystem 并使用隐式Materializer。正如文档中所写,Materializer 提供为 out of the box

      在您的代码中,只需删除 Materializer 的显式创建

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-05-15
        • 2017-05-29
        • 1970-01-01
        • 2020-07-09
        • 1970-01-01
        • 2019-04-23
        • 2014-03-09
        相关资源
        最近更新 更多