Handling multi tenant application with Axon

Hello everyone,

we have a web app that use the following use case to handle multi-tenancy:

  • a custom HTTP Header that specify the tenant
  • a spring http filter that read the Header and set the value in a ThreadLocal
  • the instance of mongodb is set with the value previously saved in ThreadLocal

Now we have started the refactoring to put Axon in our web app.
We have a couple of questions about “How to handle multi-tenant” within our implementation:

  • does exist an axon component that we can use like our “filter” in order to resolve the tenant in our way before the execution of a method annotated with @EventHandler?
  • does exist a way to have an event store instance or an event sourcing repository that change at runtime and that is per thread?
  • does exist a way to call event handler methods on existing spring beans, without using reflection but using spring context?

Any help would be appreciated :slight_smile:

Best regards,

In the JPA world you could implement your own Axon EntityManagerProvider and TransactionManager.
The implementation is injected into the JpaEventStore and is based on ThreadLocals so can provide different EntityManagers for different Tenants.
I never used really Mongo with Axon but you could start from MongoEventStore and your implementation of MongoTemplate.