Reactive Programming - Project Reactor - Sinks.Many
Sinks
https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Sinks.html
Sinks are constructs through which Reactive Streams signals can be programmatically pushed, with Flux or Mono semantics. These standalone sinks expose tryEmit methods that return an Sinks.EmitResult enum, allowing to atomically fail in case the attempted signal is inconsistent with the spec and/or the state of the sink.
This class exposes a collection of Sinks.Many builders and Sinks.One factories. These sinks are thread safe in the sense that they will detect concurrent access and fail fast on one of the attempts.
Sinks.One
https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Sinks.One.html
public static <T> Sinks.One<T> one()
- A Sinks.One that works like a conceptual promise: it can be completed with or without a value at any time, but only once.
- This completion is replayed to late subscribers.
- Calling Sinks.One.tryEmitValue(Object) (or Sinks.One.emitValue(Object, Sinks.EmitFailureHandler)) is enough and will implicitly produce a Subscriber.onComplete() signal as well.
- Use Sinks.One.asMono() to expose the Mono view of the sink to downstream consumers.
Sinks.Many
https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Sinks.Many.html
A base interface for standalone Sinks with Flux semantics.
public interface Many<T> extends Scannable {
EmitResult tryEmitNext(T var1);
EmitResult tryEmitComplete();
EmitResult tryEmitError(Throwable var1);
void emitNext(T var1, EmitFailureHandler var2);
void emitComplete(EmitFailureHandler var1);
void emitError(Throwable var1, EmitFailureHandler var2);
int currentSubscriberCount();
Flux<T> asFlux();
}
Sinks.Many<T> onBackpressureBuffer()
public abstract <T> Sinks.Many<T> onBackpressureBuffer()
A Sinks.Many with the following characteristics:
- Unicast: contrary to most other Sinks.Many, the Flux view rejects subscribers past the first one.
- Backpressure : this sink honors downstream demand of its single Subscriber.
- Replaying: non-applicable, since only one Subscriber can register.
- Without Subscriber: all elements pushed to this sink are remembered and will be replayed once the Subscriber subscribes.
Sinks.ManySpec
https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Sinks.Many.html
public static Sinks.ManySpec many()
- Help building Sinks.Many sinks that will broadcast multiple signals to one or more Subscriber.
- Use Sinks.Many.asFlux() to expose the Flux view of the sink to the downstream consumers.
Sinks.UnicastSpec
https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Sinks.UnicastSpec.html
public abstract Sinks.UnicastSpec unicast()
- Provides unicast: 1 sink, 1 Subscriber
- Help building Sinks.Many that will broadcast signals to a single Subscriber.
Sinks.MulticastSpec
https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Sinks.MulticastSpec.html
public abstract Sinks.MulticastSpec multicast()
- Provides multicast : 1 sink, N Subscriber
- Help building Sinks.Many that will broadcast signals to multiple Subscriber
Sinks.MulticastReplaySpec
public abstract Sinks.MulticastReplaySpec replay()
- Provides multicast with history/replay capacity : 1 sink, N Subscriber
- Help building Sinks.Many that will broadcast signals to multiple Subscriber with the ability to retain and replay all or an arbitrary number of elements.