public interface EventStore extends EventBus, StreamableMessageSource<TrackedEventMessage<?>>, DomainEventSequenceAware
Modifier and Type | Method and Description |
---|---|
default Optional<Long> |
lastSequenceNumberFor(String aggregateIdentifier)
Returns the last known sequence number of an Event for the given
aggregateIdentifier . |
DomainEventStream |
readEvents(String aggregateIdentifier)
Open an event stream containing all domain events belonging to the given
aggregateIdentifier . |
default DomainEventStream |
readEvents(String aggregateIdentifier,
long firstSequenceNumber)
Open an event stream containing all domain events belonging to the given
aggregateIdentifier . |
void |
storeSnapshot(DomainEventMessage<?> snapshot)
Stores the given (temporary)
snapshot event. |
subscribe
registerDispatchInterceptor
createHeadToken, createTailToken, createTokenAt, createTokenSince, openStream
DomainEventStream readEvents(@Nonnull String aggregateIdentifier)
aggregateIdentifier
.
The returned stream is finite, ending with the last known event of the aggregate. If the event store holds no events of the given aggregate an empty stream is returned.
aggregateIdentifier
- the identifier of the aggregate whose events to fetchdefault DomainEventStream readEvents(@Nonnull String aggregateIdentifier, long firstSequenceNumber)
aggregateIdentifier
.
The returned stream is finite, ending with the last known event of the aggregate. If the event store holds no events of the given aggregate an empty stream is returned.
The default implementation invokes readEvents(String)
and then filters out events with a sequence number
smaller than firstSequenceNumber
.
aggregateIdentifier
- the identifier of the aggregate whose events to fetchfirstSequenceNumber
- the expected sequence number of the first event in the returned streamvoid storeSnapshot(@Nonnull DomainEventMessage<?> snapshot)
snapshot
event. This snapshot replaces the segment of the event stream
identified by the snapshot
's Aggregate Identifier
up
to (and including) the event with the snapshot
's sequence
number
.
These snapshots will only affect the DomainEventStream
returned by the readEvents(String)
method. They do not change the events returned by StreamableMessageSource.openStream(TrackingToken)
or those received
by using SubscribableMessageSource.subscribe(java.util.function.Consumer)
.
Note that snapshots are considered a temporary replacement for Events, and are used as performance optimization. Event Store implementations may choose to ignore or delete snapshots.
snapshot
- The snapshot to replace part of the DomainEventStream.default Optional<Long> lastSequenceNumberFor(String aggregateIdentifier)
DomainEventSequenceAware
aggregateIdentifier
.
It is preferred to retrieve the last known sequence number from the Domain Event Stream when sourcing an Aggregate from events. However, this method provides an alternative in cases no events have been read. For example when using state storage.
lastSequenceNumberFor
in interface DomainEventSequenceAware
aggregateIdentifier
- the identifier of the aggregate to find the highest sequence forCopyright © 2010–2024. All rights reserved.