Interface EventStore

All Superinterfaces:
DomainEventSequenceAware, EventBus, MessageDispatchInterceptorSupport<EventMessage<?>>, StreamableMessageSource<TrackedEventMessage<?>>, SubscribableMessageSource<EventMessage<?>>
All Known Implementing Classes:
AbstractEventStore, AxonServerEventStore, EmbeddedEventStore, EmbeddedEventStore

Provides a mechanism to open streams from events in the the underlying event storage.

The EventStore provides access to both the global event stream comprised of all domain and application events, as well as streams containing only events of a single aggregate.

Author:
Allard Buijze, Rene de Waele
  • Method Details

    • readEvents

      DomainEventStream readEvents(@Nonnull String aggregateIdentifier)
      Open an event stream containing all domain events belonging to the given 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.

      Parameters:
      aggregateIdentifier - the identifier of the aggregate whose events to fetch
      Returns:
      a stream of all currently stored events of the aggregate
    • readEvents

      default DomainEventStream readEvents(@Nonnull String aggregateIdentifier, long firstSequenceNumber)
      Open an event stream containing all domain events belonging to the given 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.

      Parameters:
      aggregateIdentifier - the identifier of the aggregate whose events to fetch
      firstSequenceNumber - the expected sequence number of the first event in the returned stream
      Returns:
      a stream of all currently stored events of the aggregate
    • storeSnapshot

      void storeSnapshot(@Nonnull DomainEventMessage<?> snapshot)
      Stores the given (temporary) 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.

      Parameters:
      snapshot - The snapshot to replace part of the DomainEventStream.
    • lastSequenceNumberFor

      default Optional<Long> lastSequenceNumberFor(String aggregateIdentifier)
      Description copied from interface: DomainEventSequenceAware
      Returns the last known sequence number of an Event for the given 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.

      Specified by:
      lastSequenceNumberFor in interface DomainEventSequenceAware
      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