Skip to content

Is there a Reactor operator that automatically merges signals under backpressure (mergeOnBackpressure)? #4162

@zhou-hao

Description

@zhou-hao

Question

Is there any built-in Project Reactor operator that can merge / reduce elements automatically when backpressure happens?

Conceptually, I am looking for something like:

<S, C, T> Flux<T> mergeOnBackpressure(Flux<S> source,
                                       Supplier<C> containerSupplier,
                                       BiFunction<C, S, C> merger,
                                       Predicate<C> bufferPredicate,
                                       Function<C, T> mapper,
                                       Consumer<S> onDrop)

Meaning:

  • When downstream is slower than upstream
  • Instead of buffering or dropping,
  • Reactor would automatically merge multiple incoming signals into one
  • And then emit that merged value when downstream requests next

What I Currently Know

Reactor already provides:

  • onBackpressureLatest() → keeps the latest value, effectively a special “merge = overwrite”
  • onBackpressureDrop() → drops values
  • onBackpressureBuffer() → buffers values

But there is no operator that allows a custom merge/reduce function under backpressure, for example:

  • accumulating metrics
  • merging state snapshots
  • summing counters
  • coalescing events

Typical Use Case

A typical pattern I need is:

flux
    // when downstream is slow:
    // instead of buffering or dropping,
    // merge multiple upstream values into one
    .mergeOnBackpressure(.......)
    .concatMap(this::processAsync); // ordered async processing

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions