Interface EventStore
- All Superinterfaces:
DomainEventSequenceAware,EventBus,MessageDispatchInterceptorSupport<EventMessage<?>>,StreamableMessageSource<TrackedEventMessage<?>>,SubscribableMessageSource<EventMessage<?>>
- All Known Implementing Classes:
AbstractEventStore,AxonServerEventStore,EmbeddedEventStore,EmbeddedEventStore
- Author:
- Allard Buijze, Rene de Waele
-
Method Summary
Modifier and TypeMethodDescriptionlastSequenceNumberFor(String aggregateIdentifier) Returns the last known sequence number of an Event for the givenaggregateIdentifier.readEvents(String aggregateIdentifier) Open an event stream containing all domain events belonging to the givenaggregateIdentifier.default DomainEventStreamreadEvents(String aggregateIdentifier, long firstSequenceNumber) Open an event stream containing all domain events belonging to the givenaggregateIdentifier.voidstoreSnapshot(DomainEventMessage<?> snapshot) Stores the given (temporary)snapshotevent.Methods inherited from interface org.axonframework.messaging.MessageDispatchInterceptorSupport
registerDispatchInterceptorMethods inherited from interface org.axonframework.messaging.StreamableMessageSource
createHeadToken, createTailToken, createTokenAt, createTokenSince, openStreamMethods inherited from interface org.axonframework.messaging.SubscribableMessageSource
subscribe
-
Method Details
-
readEvents
Open an event stream containing all domain events belonging to the givenaggregateIdentifier.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.
- Parameters:
aggregateIdentifier- the identifier of the aggregate whose events to fetch- Returns:
- a stream of all currently stored events of the aggregate
-
readEvents
Open an event stream containing all domain events belonging to the givenaggregateIdentifier.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 thanfirstSequenceNumber.- Parameters:
aggregateIdentifier- the identifier of the aggregate whose events to fetchfirstSequenceNumber- the expected sequence number of the first event in the returned stream- Returns:
- a stream of all currently stored events of the aggregate
-
storeSnapshot
Stores the given (temporary)snapshotevent. This snapshot replaces the segment of the event stream identified by thesnapshot'sAggregate Identifierup to (and including) the event with thesnapshot'ssequence number.These snapshots will only affect the
DomainEventStreamreturned by thereadEvents(String)method. They do not change the events returned byStreamableMessageSource.openStream(TrackingToken)or those received by usingSubscribableMessageSource.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.
- Parameters:
snapshot- The snapshot to replace part of the DomainEventStream.
-
lastSequenceNumberFor
Description copied from interface:DomainEventSequenceAwareReturns the last known sequence number of an Event for the givenaggregateIdentifier.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.
- Specified by:
lastSequenceNumberForin interfaceDomainEventSequenceAware- Parameters:
aggregateIdentifier- the identifier of the aggregate to find the highest sequence for- Returns:
- an optional containing the highest sequence number found, or an empty optional is no events are found for this aggregate
-