Interface EventStoreTransaction
- All Known Implementing Classes:
DefaultEventStoreTransaction
EventStore
based on the resulting MessageStream.
Note that this transaction includes operations for source(SourcingCondition) the model as well as
appending events.
- Since:
- 5.0.0
- Author:
- Allard Buijze, Steven van Beelen
-
Method Summary
Modifier and TypeMethodDescriptionvoidappendEvent(EventMessage eventMessage) Appends aneventMessageto be appended to anEventStorein this transaction.Returns the position in the event store of the lastappendedevent by this transaction.voidonAppend(Consumer<EventMessage> callback) Registers acallbackto invoke when an event isappendedto this transaction.default MessageStream<? extends EventMessage> source(SourcingCondition condition) Sources aMessageStreamof typeEventMessagebased on the givenconditionthat can be used to rehydrate a model.MessageStream<? extends EventMessage> source(SourcingCondition condition, @Nullable Consumer<Position> resumePositionCallback) Sources aMessageStreamof typeEventMessagebased on the givencondition, optionally invoking the givenresume positioncallback.
-
Method Details
-
source
Sources aMessageStreamof typeEventMessagebased on the givenconditionthat can be used to rehydrate a model.Note that using
no criteriadoes not make sense for sourcing, as it is not recommended to source the entire event store.Any
EventStoreTransactionusing theEventStorageEngine.source(SourcingCondition)is expected tofiltertheTerminalEventMessagewith theConsistencyMarker.- Parameters:
condition- TheSourcingConditionused to retrieve theMessageStreamcontaining the sequence of events that can rehydrate a model.- Returns:
- The
MessageStreamof typeEventMessagecontaining the event sequence complying to the givencondition.
-
source
MessageStream<? extends EventMessage> source(SourcingCondition condition, @Nullable Consumer<Position> resumePositionCallback) Sources aMessageStreamof typeEventMessagebased on the givencondition, optionally invoking the givenresume positioncallback.The provided
resumePositionCallback, if non-null, is invoked at most once and only after the returnedMessageStreamhas been consumed completely. For most implementations, theresume positionis only known when the stream reaches its terminal event. As such, the callback is guaranteed to be invoked only if the stream is fully consumed.If sourcing completes and no events are found, the callback will be invoked with the position specified in
sourcingConditionor with a greater position. Returning a greater position allows resuming from a point that already excludes positions known to be non-matching.If the stream terminates with an error, is closed prematurely, or is not consumed to completion, the callback is not guaranteed to be invoked.
The callback should not throw exceptions; doing so may result in undefined behavior.
Note that using
no criteriadoes not make sense for sourcing, as it is not recommended to source the entire event store.Any
EventStoreTransactionusing theEventStorageEngine.source(SourcingCondition)is expected tofiltertheTerminalEventMessagewith theConsistencyMarker.- Parameters:
condition- TheSourcingConditionused to retrieve theMessageStreamcontaining the sequence of events that can rehydrate a model.resumePositionCallback- An optional callback that receives thePositionfrom which sourcing may be resumed once it becomes available; the position provided is nevernull.- Returns:
- The
MessageStreamof typeEventMessagecontaining the event sequence complying to the givencondition. - Since:
- 5.0.3
-
appendEvent
Appends aneventMessageto be appended to anEventStorein this transaction.- Parameters:
eventMessage- TheEventMessageto append.
-
onAppend
Registers acallbackto invoke when an event isappendedto this transaction.Each
callbackregistration adds a new callback that is invoked on theappendEvent(EventMessage, AppendCondition)operation.- Parameters:
callback- AConsumerto invoke when an event is appended in this transaction.
-
appendPosition
ConsistencyMarker appendPosition()Returns the position in the event store of the lastappendedevent by this transaction.Will return
ConsistencyMarker.ORIGINif nothing has been appended yet.- Returns:
- The position in the event store of the last
appendedevent by this transaction.
-