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.ObjectGroup to configure replaying aMultito 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)MultiReplayupTo(long numberOfItemsToReplay)Limit the number of items each new subscriber gets.
-
-
-
Method Detail
-
upTo
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_VALUEmeans replaying all events- Returns:
- this group
-
ofMulti
public <T> Multi<T> ofMulti(Multi<T> upstream)
Create a replayMulti.Replaying work as follows.
- The provided
upstreamMultiis turned into a hot-stream as it gets requestedLong.MAX_VALUEelements. This happens at the first subscription request. Note thatupstreamwill never be cancelled. - Each new subscriber to this replay
Multiis 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
public <T> Multi<T> ofSeedAndMulti(java.lang.Iterable<T> seed, Multi<T> upstream)
Create a replayMultiwith some seed elements inserted before the providedMultiitems.The behavior is that of
ofMulti(Multi), except that the items fromseedare prepended to those fromupstreamin the replay log.- Type Parameters:
T- the items type- Parameters:
seed- the seed elements, must not benull, must not contain anynullelementupstream- theMultito replay, must not benull- Returns:
- a replaying
Multi - See Also:
ofMulti(Multi)
-
-