Mongo
The MongoEventStorageEngine
has an @PostConstruct
annotated method, called ensureIndexes
which will generate the indexes required for correct operation. That means, when running in a container that automatically calls @PostConstruct
handlers, the required unique index on "Aggregate Identifier" and "Event Sequence Number" is created when the event store is created.
Note that there is always a balance between query optimization and update speed. Load testing is ultimately the best way to discover which indices provide the best performance.
Normal operational use
An index is automatically created on
"aggregateIdentifier"
,"type"
and"sequenceNumber"
in the domain events (default name:"domainevents"
) collection. Additionally, a non-unique index on"timestamp"
and"sequenceNumber"
is configured on the domain events (default name:"domainevents"
) collection, for tracking event processors.Snapshotting
A (unique) index on
"aggregateIdentifier"
and"sequenceNumber"
is automatically created in the snapshot events (default name:"snapshotevents"
) collection.Sagas
Put a (unique) index on the
"sagaIdentifier"
in the saga (default name:"sagas"
) collection. Put an index on the"sagaType"
,"associations.key"
and"associations.value"
properties in the saga (default name:"sagas"
) collection.Dead letter queue
Put a (unique) index on the combination of
"processingGroup"
,"sequenceIdentifier"
and"index"
in the dead letter (default name:"deadletters"
) collection. Put an index on the"processingGroup"
, and"sequenceIdentifier"
properties in the dead letter (default name:"deadletters"
) collection. Put an index on the"processingGroup"
property in the dead letter (default name:"deadletters"
) collection.
In pre Axon Framework 3 release we found MongoDb to be a very good fit as an Event Store. However, with the introduction of Tracking Event Processors and how they track their events, we have encountered some inefficiencies regarding the Mongo Event Store implementation. We recommend using a built-for-purpose event store like Axon Server, or alternatively an RDBMS based (the JPA or JDBC implementations for example), and would only suggest to use Mongo for this use case if you have found its performance to be beneficial for your application.
Configuration of the Event Store with Spring
Configuration in Spring Boot
This extension can be added as a Spring Boot starter dependency to your project using group id org.axonframework.extensions.mongo
and artifact id axon-mongo-spring-boot-starter
. When using the autoconfiguration, by default the following components will be created for you automatically:
A
MongoTransactionManager
to enable transactions with Mongo.A
SpringMongoTransactionManager
, this is the wrapped Spring mongo transaction manager, and will also be injected where applicable in other components created by the auto-config.A
SpringMongoTemplate
, this will use aMongoDatabaseFactory
that should be available. To use transaction with Mongo the collections need to be accessed in a certain way, and this component makes sure of that.A
MongoTokenStore
, this will be used by the event processors to can keep track which events have been processed, and which segments are claimed.A
MongoSagaStore
, this will be used to store and retrieve saga's.
It's also possible to autoconfigure the StorageStrategy
and EventStorageEngine
by setting the mongo.event-store.enabled
to true. The creation of the token store and the saga store can be turned off by setting mongo.token-store.enabled
or mongo.saga-store.enabled
to false. It's also possible to use a different database for the axon collections than the default the MongoDatabaseFactory
uses by setting the axon.mongo.database-name
property.
The relevant configuration could look like this:
While test
is the default database name, for the axon collections the axon
database will be used instead. The saga store will not be initialised.
Configuration of the Mongo Dead-Letter Queue with Spring
See Dead-Letter Queue for the general information about the Dead-Letter Queue.
Last updated