Package io.smallrye.mutiny.groups
Class MultiReplay
- java.lang.Object
-
- io.smallrye.mutiny.groups.MultiReplay
-
@Experimental("Replaying of Multi is an experimental feature in Mutiny 1.4.0") public class MultiReplay extends java.lang.Object
Group to configure replaying aMulti
to multiple subscribers.
-
-
Constructor Summary
Constructors Constructor Description MultiReplay()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Multi<T>
ofMulti(Multi<T> upstream)
Create a replayMulti
.<T> Multi<T>
ofSeedAndMulti(java.lang.Iterable<T> seed, Multi<T> upstream)
MultiReplay
upTo(long numberOfItemsToReplay)
Limit the number of items each new subscriber gets.
-
-
-
Method Detail
-
upTo
@CheckReturnValue public MultiReplay upTo(long numberOfItemsToReplay)
Limit the number of items each new subscriber gets. The default is to replay all events.- Parameters:
numberOfItemsToReplay
- a strictly positive number of items to be replayed, whereLong.MAX_VALUE
means replaying all events- Returns:
- this group
-
ofMulti
@CheckReturnValue public <T> Multi<T> ofMulti(Multi<T> upstream)
Create a replayMulti
.Replaying work as follows.
- The provided
upstream
Multi
is turned into a hot-stream as it gets requestedLong.MAX_VALUE
elements. This happens at the first subscription request. Note thatupstream
will never be cancelled. - Each new subscriber to this replay
Multi
is able to replay items at its own pace (back-pressure is honored). - When the number of items to replay is limited using
upTo(long)
, then a new subscriber gets to replay starting from the current position in the upstream replay log. When the number of elements to replay is unbounded, then a new subscriber replays from the start. - All current and late subscribers observe terminal completion / error signals.
- Items are pushed synchronously to subscribers when they call
Subscription.request(long)
and there are enough elements to satisfy a part of the demand. Otherwise items are pushed from the upstream to all subscribers with an outstanding demand.
Replaying a large number of elements can be costly, as items have to be kept in-memory. It is NOT recommended using this operator with unbounded streams, especially as they can't be canceled (the subscribers can cancel replays, though). In such cases and especially when you have to keep replay data around for a long time then some eventing middleware might be a better fit.
- The provided
-
ofSeedAndMulti
@CheckReturnValue public <T> Multi<T> ofSeedAndMulti(java.lang.Iterable<T> seed, Multi<T> upstream)
Create a replayMulti
with some seed elements inserted before the providedMulti
items.The behavior is that of
ofMulti(Multi)
, except that the items fromseed
are prepended to those fromupstream
in the replay log.- Type Parameters:
T
- the items type- Parameters:
seed
- the seed elements, must not benull
, must not contain anynull
elementupstream
- theMulti
to replay, must not benull
- Returns:
- a replaying
Multi
- See Also:
ofMulti(Multi)
-
-