public class MongoEventStore extends Object implements SnapshotEventStore, EventStoreManagement, UpcasterAware, PartialStreamSupport
Implementation of the EventStore based on a MongoDB instance or replica set. Sharding and pairing
are not explicitly supported.
This event store implementation needs a serializer as well as a MongoTemplate to interact with the mongo database.
Warning: This implementation is still in progress and may be subject to alterations. The implementation works, but has not been optimized to fully leverage MongoDB's features, yet.
| Constructor and Description |
|---|
MongoEventStore(MongoTemplate mongo)
Constructor that uses the default Serializer.
|
MongoEventStore(MongoTemplate mongoTemplate,
Serializer eventSerializer,
StorageStrategy storageStrategy)
Initialize the mongo event store with given
mongoTemplate, eventSerializer and
storageStrategy. |
MongoEventStore(MongoTemplate mongoTemplate,
StorageStrategy storageStrategy)
Constructor that accepts a MongoTemplate and a custom StorageStrategy.
|
MongoEventStore(Serializer eventSerializer,
MongoTemplate mongo)
Constructor that accepts a Serializer and the MongoTemplate.
|
| Modifier and Type | Method and Description |
|---|---|
void |
appendEvents(String type,
DomainEventStream events)
Append the events in the given
stream to the event store. |
void |
appendSnapshotEvent(String type,
DomainEventMessage snapshotEvent)
Append the given
snapshotEvent to the snapshot event log for the given type type. |
void |
ensureIndexes()
Make sure an index is created on the collection that stores domain events.
|
MongoCriteriaBuilder |
newCriteriaBuilder()
Returns a CriteriaBuilder that allows the construction of criteria for this EventStore implementation
|
DomainEventStream |
readEvents(String type,
Object identifier)
Read the events of the aggregate identified by the given type and identifier that allow the current aggregate
state to be rebuilt.
|
DomainEventStream |
readEvents(String type,
Object identifier,
long firstSequenceNumber)
Returns a Stream containing events for the aggregate identified by the given
type and identifier, starting at the event with the given firstSequenceNumber (included). |
DomainEventStream |
readEvents(String type,
Object identifier,
long firstSequenceNumber,
long lastSequenceNumber)
Returns a Stream containing events for the aggregate identified by the given
type and identifier, starting at the event with the given firstSequenceNumber (included) up to and including the
event with given lastSequenceNumber. |
void |
setUpcasterChain(UpcasterChain upcasterChain)
Sets the UpcasterChain which allow older revisions of serialized objects to be deserialized.
|
void |
visitEvents(Criteria criteria,
EventVisitor visitor)
Loads all events available in the event store that match the given
criteria and calls EventVisitor.doWithEvent(org.axonframework.domain.DomainEventMessage) for each event found. |
void |
visitEvents(EventVisitor visitor)
Loads all events available in the event store and calls
EventVisitor.doWithEvent(org.axonframework.domain.DomainEventMessage)
for each event found. |
public MongoEventStore(Serializer eventSerializer, MongoTemplate mongo)
SerializedMetaData.isSerializedMetaData(org.axonframework.serializer.SerializedObject)eventSerializer - Your own Serializermongo - Mongo instance to obtain the database and the collections.public MongoEventStore(MongoTemplate mongo)
mongo - MongoTemplate instance to obtain the database and the collections.public MongoEventStore(MongoTemplate mongoTemplate, StorageStrategy storageStrategy)
mongoTemplate - The template giving access to the required collectionsstorageStrategy - The strategy for storing and retrieving events from the collectionspublic MongoEventStore(MongoTemplate mongoTemplate, Serializer eventSerializer, StorageStrategy storageStrategy)
mongoTemplate, eventSerializer and
storageStrategy.mongoTemplate - The template giving access to the required collectionseventSerializer - The serializer to serialize events withstorageStrategy - The strategy for storing and retrieving events from the collections@PostConstruct public void ensureIndexes()
public void appendEvents(String type, DomainEventStream events)
EventStorestream to the event store.appendEvents in interface EventStoretype - The type descriptor of the object to storeevents - The event stream containing the events to storepublic DomainEventStream readEvents(String type, Object identifier)
EventStorereadEvents in interface EventStoretype - The type descriptor of the object to retrieveidentifier - The unique aggregate identifier of the events to loadpublic DomainEventStream readEvents(String type, Object identifier, long firstSequenceNumber)
PartialStreamSupporttype and identifier, starting at the event with the given firstSequenceNumber (included).
The returned stream will not contain any snapshot events.readEvents in interface PartialStreamSupporttype - The type identifier of the aggregateidentifier - The identifier of the aggregatefirstSequenceNumber - The sequence number of the first event to findpublic DomainEventStream readEvents(String type, Object identifier, long firstSequenceNumber, long lastSequenceNumber)
PartialStreamSupporttype and identifier, starting at the event with the given firstSequenceNumber (included) up to and including the
event with given lastSequenceNumber.
If no event with given lastSequenceNumber exists, the returned stream will simply read until the end of
the aggregate's events.
The returned stream will not contain any snapshot events.readEvents in interface PartialStreamSupporttype - The type identifier of the aggregateidentifier - The identifier of the aggregatefirstSequenceNumber - The sequence number of the first event to findlastSequenceNumber - The sequence number of the last event in the streampublic void appendSnapshotEvent(String type, DomainEventMessage snapshotEvent)
SnapshotEventStoresnapshotEvent to the snapshot event log for the given type type. The
sequence number of the snapshotEvent must be equal to the sequence number of the last regular
domain
event that is included in the snapshot.
Implementations may choose to prune snapshots upon appending a new snapshot, in order to minimize storage space.appendSnapshotEvent in interface SnapshotEventStoretype - The type of aggregate the event belongs tosnapshotEvent - The event summarizing one or more domain events for a specific aggregate.public void visitEvents(EventVisitor visitor)
EventStoreManagementEventVisitor.doWithEvent(org.axonframework.domain.DomainEventMessage)
for each event found. Events of a single aggregate are guaranteed to be ordered by their sequence number.
Implementations are encouraged, though not required, to supply events in the absolute chronological order.
Processing stops when the visitor throws an exception.visitEvents in interface EventStoreManagementvisitor - The visitor the receives each loaded eventpublic void visitEvents(Criteria criteria, EventVisitor visitor)
EventStoreManagementcriteria and calls EventVisitor.doWithEvent(org.axonframework.domain.DomainEventMessage) for each event found. Events of a single
aggregate are guaranteed to be ordered by their sequence number.
Implementations are encouraged, though not required, to supply events in the absolute chronological order.
Processing stops when the visitor throws an exception.visitEvents in interface EventStoreManagementcriteria - The criteria describing the events to selectvisitor - The visitor the receives each loaded eventEventStoreManagement.newCriteriaBuilder()public MongoCriteriaBuilder newCriteriaBuilder()
EventStoreManagementnewCriteriaBuilder in interface EventStoreManagementEventStoreManagement.visitEvents(Criteria, org.axonframework.eventstore.EventVisitor)public void setUpcasterChain(UpcasterChain upcasterChain)
UpcasterAwaresetUpcasterChain in interface UpcasterAwareupcasterChain - the upcaster chain providing the upcasting capabilitiesCopyright © 2010-2014. All Rights Reserved.