Class MultiTenancyPersistentStreamAutoConfiguration

java.lang.Object
io.axoniq.framework.springboot.autoconfig.MultiTenancyPersistentStreamAutoConfiguration

@AutoConfiguration(before=PersistentStreamAutoConfiguration.class) @ConditionalOnClass(MultiTenancyConfigurationDefaults.class) public class MultiTenancyPersistentStreamAutoConfiguration extends Object
Spring Boot auto-configuration making persistent streams multi-tenant, by replacing the PersistentStreamEventSourceFactory with one that builds a MultiTenantPersistentStreamEventSource per configured stream.

Nothing else changes for an application: streams stay configured under axon.axonserver.persistent-streams and are still referenced by axon.eventhandling.processors.<name>.source, but each one is now consumed from every tenant's Axon Server context, and every event reaches its handlers labelled with the tenant it belongs to. A projection therefore lands in the right tenant's data source as soon as its handler takes a TenantScoped parameter.

Runs before PersistentStreamAutoConfiguration, whose @ConditionalOnMissingBean factory then backs off. Declaring a PersistentStreamEventSourceFactory bean of your own takes precedence over both, which is the way to control how each tenant's stream is built.

Contributes the factory only while multi-tenancy applies, reusing the condition MultiTenancyAutoConfiguration switches itself off by, so it steps aside for exactly the reasons multi-tenancy itself is inactive. On top of that it needs persistent streams to exist at all, which is what axon.axonserver.event-store.enabled decides, the same property PersistentStreamAutoConfiguration gates its own beans on.

Since:
5.3.0
Author:
Jakob Hatzl
See Also:
  • Constructor Details

    • MultiTenancyPersistentStreamAutoConfiguration

      public MultiTenancyPersistentStreamAutoConfiguration()
  • Method Details

    • multiTenantPersistentStreamEventSourceFactory

      @Bean @ConditionalOnMissingBean @Conditional(io.axoniq.framework.springboot.autoconfig.MultiTenancyPersistentStreamAutoConfiguration.MultiTenancyApplies.class) @ConditionalOnProperty(name="axon.axonserver.event-store.enabled", matchIfMissing=true) public PersistentStreamEventSourceFactory multiTenantPersistentStreamEventSourceFactory()
      Creates the PersistentStreamEventSourceFactory building a per-tenant fan-out for every configured persistent stream.
      Returns:
      the multi-tenant PersistentStreamEventSourceFactory