public class MongoEventStorageEngine extends BatchingEventStorageEngine
Constructor and Description |
---|
MongoEventStorageEngine(MongoTemplate template)
Initializes an EventStorageEngine that uses Mongo to store and load events.
|
MongoEventStorageEngine(Serializer serializer,
EventUpcaster upcasterChain,
Integer batchSize,
MongoTemplate template,
StorageStrategy storageStrategy)
Initializes an EventStorageEngine that uses Mongo to store and load events.
|
MongoEventStorageEngine(Serializer serializer,
EventUpcaster upcasterChain,
MongoTemplate template,
StorageStrategy storageStrategy)
Initializes an EventStorageEngine that uses Mongo to store and load events.
|
MongoEventStorageEngine(Serializer snapshotSerializer,
EventUpcaster upcasterChain,
PersistenceExceptionResolver persistenceExceptionResolver,
Serializer eventSerializer,
Integer batchSize,
MongoTemplate template,
StorageStrategy storageStrategy)
Initializes an EventStorageEngine that uses Mongo to store and load events.
|
MongoEventStorageEngine(Serializer snapshotSerializer,
EventUpcaster upcasterChain,
Serializer eventSerializer,
Integer batchSize,
MongoTemplate template,
StorageStrategy storageStrategy)
Initializes an EventStorageEngine that uses Mongo to store and load events.
|
MongoEventStorageEngine(Serializer snapshotSerializer,
EventUpcaster upcasterChain,
Serializer eventSerializer,
MongoTemplate template,
StorageStrategy storageStrategy)
Initializes an EventStorageEngine that uses Mongo to store and load events.
|
Modifier and Type | Method and Description |
---|---|
protected void |
appendEvents(List<? extends EventMessage<?>> events,
Serializer serializer)
Append given
events to the backing database. |
TrackingToken |
createHeadToken()
Creates a token that is at the head of an event stream - that tracks all new events.
|
TrackingToken |
createTailToken()
Creates a token that is at the tail of an event stream - that tracks events from the beginning of time.
|
TrackingToken |
createTokenAt(Instant dateTime)
Creates a token that tracks all events after given
dateTime . |
void |
ensureIndexes()
Make sure an index is created on the collection that stores domain events.
|
protected List<? extends DomainEventData<?>> |
fetchDomainEvents(String aggregateIdentifier,
long firstSequenceNumber,
int batchSize)
Returns a batch of events published by an aggregate with given
aggregateIdentifier . |
protected List<? extends TrackedEventData<?>> |
fetchTrackedEvents(TrackingToken lastToken,
int batchSize)
Returns a batch of serialized event data entries in the event storage that have a
TrackingToken greater
than the given lastToken . |
Optional<Long> |
lastSequenceNumberFor(String aggregateIdentifier)
Returns the last known sequence number for the given
aggregateIdentifier . |
protected Optional<? extends DomainEventData<?>> |
readSnapshotData(String aggregateIdentifier)
Returns an optional serialized event entry for given
aggregateIdentifier if the backing database
contains a snapshot of the aggregate. |
protected void |
storeSnapshot(DomainEventMessage<?> snapshot,
Serializer serializer)
Store the given
snapshot of an Aggregate. |
batchSize, readEventData, readEventData
appendEvents, getEventSerializer, getSerializer, handlePersistenceException, readEvents, readEvents, readSnapshot, storeSnapshot
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
appendEvents, readEvents
public MongoEventStorageEngine(MongoTemplate template)
The payload and metadata of events is stored as a serialized blob of bytes using a new XStreamSerializer
.
Events are read in batches of 100. No upcasting is performed after the events have been fetched.
template
- MongoTemplate instance to obtain the database and the collections.public MongoEventStorageEngine(Serializer serializer, EventUpcaster upcasterChain, MongoTemplate template, StorageStrategy storageStrategy)
Serializer
is used for both snapshots and events.serializer
- Used to serialize and deserialize event payload and metadata, and snapshots.upcasterChain
- Allows older revisions of serialized objects to be deserialized.template
- MongoTemplate instance to obtain the database and the collections.storageStrategy
- The strategy for storing and retrieving events from the collections.public MongoEventStorageEngine(Serializer snapshotSerializer, EventUpcaster upcasterChain, Serializer eventSerializer, MongoTemplate template, StorageStrategy storageStrategy)
snapshotSerializer
- Used to serialize and deserialize snapshots.upcasterChain
- Allows older revisions of serialized objects to be deserialized.eventSerializer
- Used to serialize and deserialize event payload and metadata.template
- MongoTemplate instance to obtain the database and the collections.storageStrategy
- The strategy for storing and retrieving events from the collections.public MongoEventStorageEngine(Serializer serializer, EventUpcaster upcasterChain, Integer batchSize, MongoTemplate template, StorageStrategy storageStrategy)
Serializer
is used for both snapshots and
events.serializer
- Used to serialize and deserialize event payload and metadata, and snapshots.upcasterChain
- Allows older revisions of serialized objects to be deserialized.batchSize
- The number of events that should be read at each database access. When more than this
number of events must be read to rebuild an aggregate's state, the events are read in
batches of this size. Tip: if you use a snapshotter, make sure to choose snapshot trigger
and batch size such that a single batch will generally retrieve all events required to
rebuild an aggregate's state.template
- MongoTemplate instance to obtain the database and the collections.storageStrategy
- The strategy for storing and retrieving events from the collections.public MongoEventStorageEngine(Serializer snapshotSerializer, EventUpcaster upcasterChain, Serializer eventSerializer, Integer batchSize, MongoTemplate template, StorageStrategy storageStrategy)
snapshotSerializer
- Used to serialize and deserialize snapshots.upcasterChain
- Allows older revisions of serialized objects to be deserialized.eventSerializer
- Used to serialize and deserialize event payload and metadata.batchSize
- The number of events that should be read at each database access. When more than this
number of events must be read to rebuild an aggregate's state, the events are read in
batches of this size. Tip: if you use a snapshotter, make sure to choose snapshot trigger
and batch size such that a single batch will generally retrieve all events required to
rebuild an aggregate's state.template
- MongoTemplate instance to obtain the database and the collections.storageStrategy
- The strategy for storing and retrieving events from the collections.public MongoEventStorageEngine(Serializer snapshotSerializer, EventUpcaster upcasterChain, PersistenceExceptionResolver persistenceExceptionResolver, Serializer eventSerializer, Integer batchSize, MongoTemplate template, StorageStrategy storageStrategy)
snapshotSerializer
- Used to serialize and deserialize snapshots.upcasterChain
- Allows older revisions of serialized objects to be deserialized.persistenceExceptionResolver
- Custom resolver of persistence errors.eventSerializer
- Used to serialize and deserialize event payload and metadata.batchSize
- The number of events that should be read at each database access. When more
than this number of events must be read to rebuild an aggregate's state, the
events are read in batches of this size. Tip: if you use a snapshotter, make
sure to choose snapshot trigger and batch size such that a single batch will
generally retrieve all events required to rebuild an aggregate's state.template
- MongoTemplate instance to obtain the database and the collections.storageStrategy
- The strategy for storing and retrieving events from the collections.@PostConstruct public void ensureIndexes()
protected void appendEvents(List<? extends EventMessage<?>> events, Serializer serializer)
AbstractEventStorageEngine
events
to the backing database. Use the given serializer
to serialize the event's
payload and metadata.appendEvents
in class AbstractEventStorageEngine
events
- Events to append to the databaseserializer
- Serializer used to convert the events to a suitable format for storageprotected void storeSnapshot(DomainEventMessage<?> snapshot, Serializer serializer)
AbstractEventStorageEngine
snapshot
of an Aggregate. Implementations may override any existing snapshot of the
Aggregate with the given snapshot.storeSnapshot
in class AbstractEventStorageEngine
snapshot
- Snapshot Event of the aggregateserializer
- Serializer used to convert the snapshot event to a suitable format for storageprotected Optional<? extends DomainEventData<?>> readSnapshotData(String aggregateIdentifier)
AbstractEventStorageEngine
aggregateIdentifier
if the backing database
contains a snapshot of the aggregate.readSnapshotData
in class AbstractEventStorageEngine
aggregateIdentifier
- The aggregate identifier to fetch a snapshot forprotected List<? extends DomainEventData<?>> fetchDomainEvents(String aggregateIdentifier, long firstSequenceNumber, int batchSize)
BatchingEventStorageEngine
aggregateIdentifier
.
The sequence numbers in the returned batch should be ordered by sequence number. The first event in the batch
should have a sequence number equal to or larger than given firstSequenceNumber
. Implementations should
make sure the returned batch does not contain gaps between events due to uncommitted storage transactions.
If the returned number of entries is smaller than the given batchSize
it is assumed that the storage
holds no further applicable entries.fetchDomainEvents
in class BatchingEventStorageEngine
aggregateIdentifier
- The identifier of the aggregate to open a stream forfirstSequenceNumber
- The sequence number of the first excepted event entrybatchSize
- The maximum number of events that should be returnedprotected List<? extends TrackedEventData<?>> fetchTrackedEvents(TrackingToken lastToken, int batchSize)
BatchingEventStorageEngine
TrackingToken
greater
than the given lastToken
. Event entries in the stream should be ordered by tracking token. If the lastToken
is null
a stream containing all events should be returned.
Only if the returned List is empty the event storage assumes that the backing database holds no further applicable entries.
fetchTrackedEvents
in class BatchingEventStorageEngine
lastToken
- Object describing the global index of the last processed event or null
to create a
stream of all events in the storebatchSize
- The maximum number of events that should be returnedpublic Optional<Long> lastSequenceNumberFor(String aggregateIdentifier)
EventStorageEngine
aggregateIdentifier
.
While it's recommended to use the sequence numbers from the DomainEventStream
, there are cases where
knowing the sequence number is required, without having read the actual events. In such case, this method is a
viable alternative.
aggregateIdentifier
- The identifier to find the last sequence number forpublic TrackingToken createTailToken()
EventStorageEngine
null
is returnedpublic TrackingToken createHeadToken()
EventStorageEngine
null
is returnedpublic TrackingToken createTokenAt(Instant dateTime)
EventStorageEngine
dateTime
. If there is an event exactly at the given
dateTime
, it will be tracked too.dateTime
- The date and time for determining criteria how the tracking token should be created. A tracking
token should point to very first event before this date and time.dateTime
, if there aren't events matching this criteria null
is returnedCopyright © 2010–2018. All rights reserved.