Hi Allard, nice to meet you.
I have been watching your live code demos for a long time by now. It’s like I know you. Lol
PS: sorry about my bad english.
there are different ways to implement multi-tenancy in Axon. If you use multitenancy on the datasource level, there are some restrictions, though. The TrackingProcessor, for example, doesn’t support this (yet). The rest of the components should not have any issues.
We are using tenancy with database SCHEMA. New schemas are created on ‘fly’ with liquibase by just passing few extra information on HEADERs request. This allow us to create a new database for a new client without any redeploy/restart.
spring.jpa.properties.hibernate.multiTenancy=SCHEMA
spring.jpa.properties.hibernate.tenant_identifier_resolver=br.com.zup.realwave.common.tenant.context.CurrentTenantIdentifier
spring.jpa.properties.hibernate.multi_tenant_connection_provider=br.com.zup.realwave.common.tenant.provider.PostgreSqlMultiTenantConnectionProvider
I couldnt make Axon 3 create my tables alone in this case. I’m not sure if is my fault and I missing some configuration tho. Well, not a big problem, I just started one simply Axon Springboot app at start.spring.io without no tenancy and I copy past the DDL to my liquibase changelog files. Still I’m worry about what I will do when Axon change the DDLs.
If you use Hibernate/JPA, you can override any configuration defined by annotations. I haven’t used it myself, but apparantly there are ways (using XML, though) to override the definitions.
Alternatively, you can extend the JpaEventStorageEngine and implement the domainEventEntryEntityName and createEventEntity methods. This allows you to use your own entities. Note that these entities must have the same properties defined as the original Axon entities. Some projects use this to add additional columns to the event store, or -just like what you’d want- change some of the properties that are generated by default.
In that simple SB + Axon 3 app that I used to copy the DDL, I can see the ‘hibernate_sequence’ created if I have this option on my application.properties so the app runs fine.
spring.jpa.hibernate.ddl-auto=create
Still, I really dont like this. I will dig a little more to try make the DomainEventEntry (and others tables) use his own sequence, and the others tables too. Override JpaEventStorageEngine looks too much, idk.
Anyway, as a suggestion, I would ask you guys (maybe I could help) to add the DDL info in the official Axon’s documentation page.
Thank you so much for the answer, Allard. Really.