Skip to content

Commit 2159f99

Browse files
Gerard Klijsgklijs
authored andcommitted
Update to Mongo Extension 4.7.0
1 parent 1b48d45 commit 2159f99

File tree

1 file changed

+51
-6
lines changed

1 file changed

+51
-6
lines changed

extensions/mongo.md

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ Note that there is always a balance between query optimization and update speed.
1616

1717
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.
1818

19+
* Dead letter queue
20+
21+
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.
22+
1923
{% hint style="info" %}
20-
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 in regards to the Mongo Event Store implementation. We recommend using a built-for-purpose event store like [Axon Server](../axon-server-introduction.md), 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.
24+
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](../axon-server-introduction.md), 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.
2125
{% endhint %}
2226

23-
## Configuration in Spring Boot
27+
## Configuration of the Event Store with Spring
2428

2529
```java
2630
@Configuration
@@ -41,14 +45,55 @@ public class AxonConfig {
4145

4246
// The MongoEventStorageEngine stores each event in a separate MongoDB document.
4347
@Bean
44-
public EventStorageEngine storageEngine(MongoClient client) {
48+
public EventStorageEngine storageEngine(MongoDatabaseFactory factory,
49+
TransactionManager transactionManager) {
4550
return MongoEventStorageEngine.builder()
46-
.mongoTemplate(DefaultMongoTemplate.builder()
47-
.mongoDatabase(client)
48-
.build())
51+
.mongoTemplate(SpringMongoTemplate.builder()
52+
.factory(factory)
53+
.build())
54+
.transactionManager(transactionManager)
4955
// ...
5056
.build();
5157
}
5258
}
5359
```
5460

61+
## Configuration in Spring Boot
62+
63+
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:
64+
* A `MongoTransactionManager` to enable transactions with Mongo.
65+
* 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.
66+
* A `SpringMongoTemplate`, this will use a `MongoDatabaseFactory` 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.
67+
* A `MongoTokenStore`, this will be used by the event processors to can keep track which events have been processed, and which segments are claimed.
68+
* A `MongoSagaStore`, this will be used to store and retrieve saga's.
69+
70+
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.
71+
72+
## Configuration of the Mongo Dead-Letter Queue with Spring
73+
74+
See [Dead-Letter Queue](../axon-framework/events/event-processors/README.md#dead-letter-queue) for the general information about the Dead-Letter Queue.
75+
76+
```java
77+
@Configuration
78+
public class AxonConfig {
79+
// omitting other configuration methods...
80+
@Bean
81+
public ConfigurerModule deadLetterQueueConfigurerModule(
82+
MongoTemplate mongoTemplate
83+
) {
84+
// Replace "my-processing-group" for the processing group you want to configure the DLQ on.
85+
return configurer -> configurer.eventProcessing().registerDeadLetterQueue(
86+
"my-processing-group",
87+
config -> MongoSequencedDeadLetterQueue.builder()
88+
.processingGroup("my-processing-group")
89+
.maxSequences(256)
90+
.maxSequenceSize(256)
91+
.mongoTemplate(mongoTemplate)
92+
.transactionManager(config.getComponent(TransactionManager.class))
93+
.serializer(config.serializer())
94+
.build()
95+
);
96+
}
97+
}
98+
```
99+

0 commit comments

Comments
 (0)