I am are using Axon Server/Framework for our event sourcing applications, and was tasked to use Axon-Mongo extension to use MongoDB as our embedded event store. (here is the Axon’s documentation that I am using)
Using the Spring Boot Autoconfiguration option suggested in the link above, I can successfully store command services events in MongoDB. However, all of the events are stored in the “domainevents” collection. Our applications are multi-tenant with “row level” (meaning I have “tenant id” in all entities, events, queries; and I am using shared DBs, schemas, tables, etc.).
For example: this is what I currently have:
HOST: somehost-cosmos-mongo.mongo.cosmos.azure.com:
|
|
|__ MONGODB: micro-serivce-ONE-db
| |__ domainevents collection // all events of all tenants are here
| |__ snapshotevents collection
|
| …
|__ MONGODB: micro-serivce-TWO-db
| |__ domainevents collection // all events of all tenants are here
| |__ snapshotevents collection
And I want to store each tenant’s events in its own collection, like below:
HOST: somehost-cosmos-mongo.mongo.cosmos.azure.com:
|
|
|__ MONGODB: micro-serivce-ONE-db
| |__ TENANT-ONE-domainevents collection // TENANT ONE’s events are here
| |__ TENANT-ONE-snapshotevents collection
|
| …
|__ MONGODB: micro-serivce-TWO-db
| |__ TENANT-TWO-domainevents collection // TENANT TWO’s events are here
| |__ TENANT-TWO-snapshotevents collection
Currently I can’t find any documentation or sample code that suggests we can do or should do the “one tenant per collection” approach. From the Spring Boot autoconfiguration sample code provided by Axon, it seems that the database/name, domain-events collection/name, and snapshot-events collection/name are created that Spring Boot autoconfiguration time (which I can override the default names) but I can’t dynamically create multiple collections at run-time and route new events to them (as I discover new tenants).
Your advice or suggestions are very much appreciated.
For reference, I am using Java 11, and the following pom dependencies:
<!-- Axon Mongo spring-boot "starter" dependencies -->
<dependency>
<groupId>org.axonframework.extensions.mongo</groupId>
<artifactId>axon-mongo-spring-boot-starter</artifactId>
<version>4.9.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>