【问题标题】:How to set OverflowStrategy in Spring Webflux?如何在 Spring Webflux 中设置 OverflowStrategy?
【发布时间】:2020-04-30 07:47:39
【问题描述】:

是否可以在 Webflux 中设置溢出策略,就像对任何其他 Sink 所做的那样?见https://projectreactor.io/docs/core/release/api/reactor/core/publisher/FluxSink.OverflowStrategy.html

默认行为似乎是:

FluxSink.OverflowStrategy BUFFER 全部缓冲 如果下游无法跟上,则发出信号。警告!这没有限制 缓冲,可能会导致 OutOfMemoryError。

我正在寻找一种将其更改为 DROP 或 ERROR 的方法:(请参阅https://projectreactor.io/docs/core/release/api/reactor/core/publisher/FluxSink.OverflowStrategy.html

【问题讨论】:

  • WebFlow?不太明白你的意思
  • 错字对不起,WebFlux
  • @YauhenBalykin 可以应用于控制器方法内的服务调用。我想知道是否有办法在容器级别设置行为?
  • 你是如何创建接收器的,例如使用通量处理器时默认为ignore

标签: spring-webflux project-reactor reactor-netty


【解决方案1】:

如果您使用Flux.create 来发出值,我们可以将FluxSink.OverflowStrategy.DROP 作为附加参数传递。

如果你使用EmitterProcessor /Any 处理器,sink 方法接受OverflowStrategy

    EmitterProcessor<Object> emitterProcessor = EmitterProcessor.create();
    FluxSink<Object> sink = emitterProcessor.sink(FluxSink.OverflowStrategy.DROP);

    // you should use sink to publish values
    sink.next(obj);

【讨论】:

  • 我说的是webflux,如何在容器中设置策略
猜你喜欢
  • 1970-01-01
  • 2018-02-24
  • 2022-09-23
  • 2018-08-06
  • 2020-05-30
  • 2022-11-03
  • 2022-12-15
  • 2018-08-09
  • 2018-07-14
相关资源
最近更新 更多