Akka流中丢弃消息的处理

Akka流中丢弃消息的处理,akka,akka-stream,Akka,Akka Stream,我有以下源队列定义 lazy val (processMessageSource, processMessageQueueFuture) = peekMatValue( Source .queue[(ProcessMessageInputData, Promise[ProcessMessageOutputData])](5, OverflowStrategy.dropNew)) def peekMatValue[T, M](src: Source[T, M]

我有以下源队列定义

lazy val (processMessageSource, processMessageQueueFuture) =
   peekMatValue(
      Source
        .queue[(ProcessMessageInputData, Promise[ProcessMessageOutputData])](5, OverflowStrategy.dropNew))


def peekMatValue[T, M](src: Source[T, M]): (Source[T, M], Future[M])  {
    val p = Promise[M]
    val s = src.mapMaterializedValue { m =>
      p.trySuccess(m)
      m
    }  
    (s, p.future)
  }
流程消息输入数据类本质上是一个工件,调用方调用连接到此流的web服务器端点时创建该工件(即,服务端点的业务逻辑将消息放入此队列)。处理消息输出的承诺是在应用程序接收器的下游完成的,然后web服务器在此将来有一个on complete回调来返回响应

还有其他进入该流的来源

现在可以备份缓冲器,因为另一个源可能会使系统过载,从而触发流背压。现有代码只是删除新消息。但我仍然希望完成流程消息输出承诺,以完成一个异常,声明类似“Throttled”的内容

是否有一种机制来编写自定义溢出策略,或对溢出元素进行后处理,从而允许我这样做

根据

dropNew会很好用的。在客户端,它看起来像

processMessageQueue.offer(in, pr).foreach { res =>
  res match {
    case Enqueued => // Code to handle case when successfully enqueued. 
    case Dropped => // Code to handle messages that are dropped since the buffier was overflowing. 
  }
}

dropNew会很好用的。在客户端,它看起来像

processMessageQueue.offer(in, pr).foreach { res =>
  res match {
    case Enqueued => // Code to handle case when successfully enqueued. 
    case Dropped => // Code to handle messages that are dropped since the buffier was overflowing. 
  }
}

默认策略是删除元素,您只需将
OverflowStrategy
更改为
backpressure()
。检查文档:,TYea但对源队列的背压意味着什么?默认策略是删除元素,您只需将
OverflowStrategy
更改为
backpressure()
。检查文档:,TYea,但对源队列施加反压力意味着什么?