From 702a64e39bc85550f15a2b3a33e874d3c7d01ea8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 31 Jul 2024 12:56:37 +0200 Subject: [PATCH 1/2] configure MultiTenancyAxonServerAutoConfiguration before AxonServerAutoConfiguration --- .../MultiTenancyAutoConfigurationTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/multitenancy-spring-boot-autoconfigure/src/test/java/org/axonframework/extensions/multitenancy/autoconfig/MultiTenancyAutoConfigurationTest.java b/multitenancy-spring-boot-autoconfigure/src/test/java/org/axonframework/extensions/multitenancy/autoconfig/MultiTenancyAutoConfigurationTest.java index a8841f0..c939d2d 100644 --- a/multitenancy-spring-boot-autoconfigure/src/test/java/org/axonframework/extensions/multitenancy/autoconfig/MultiTenancyAutoConfigurationTest.java +++ b/multitenancy-spring-boot-autoconfigure/src/test/java/org/axonframework/extensions/multitenancy/autoconfig/MultiTenancyAutoConfigurationTest.java @@ -16,6 +16,7 @@ package org.axonframework.extensions.multitenancy.autoconfig; +import org.axonframework.axonserver.connector.event.axon.PersistentStreamMessageSource; import org.axonframework.axonserver.connector.event.axon.PersistentStreamMessageSourceFactory; import org.axonframework.extensions.multitenancy.components.TargetTenantResolver; import org.axonframework.extensions.multitenancy.components.TenantConnectPredicate; @@ -39,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mock; /** * Test class validating the multi-tenancy auto-configuration. @@ -121,6 +123,22 @@ void multiTenancyDisabled() { }); } + @Test + void multiTenancyAutoConfigurationMultiTenantPersistentStreamMessageSource() { + contextRunner + .withConfiguration(AutoConfigurations.of(AxonServerAutoConfiguration.class)) + + .withConfiguration(AutoConfigurations.of(MultiTenancyAxonServerAutoConfiguration.class)) + .withConfiguration(AutoConfigurations.of(MultiTenantPersistentStreamAutoConfiguration.class)) + .withPropertyValues("axon.axonserver.contexts=tenant-1,tenant-2") + .run(context -> { + PersistentStreamMessageSourceFactory persistentStreamMessageSourceFactory = + context.getBean("persistentStreamMessageSourceFactory", PersistentStreamMessageSourceFactory.class); + PersistentStreamMessageSource persistentStreamMessageSource = persistentStreamMessageSourceFactory.build("testName", mock(), mock(), 100, "testContext", mock()); + assertThat(persistentStreamMessageSource).isInstanceOf(MultiTenantPersistentStreamMessageSource.class); + }); + } + @Test void multiTenancyMetaDataHelperDisabled() { TargetTenantResolver> userResolver = (message, tenants) -> From 5596b5e45215b8d801afea89f67cc7c968fe21cc Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 31 Jul 2024 12:56:41 +0200 Subject: [PATCH 2/2] configure MultiTenancyAxonServerAutoConfiguration before AxonServerAutoConfiguration --- .../autoconfig/MultiTenancyAxonServerAutoConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multitenancy-spring-boot-autoconfigure/src/main/java/org/axonframework/extensions/multitenancy/autoconfig/MultiTenancyAxonServerAutoConfiguration.java b/multitenancy-spring-boot-autoconfigure/src/main/java/org/axonframework/extensions/multitenancy/autoconfig/MultiTenancyAxonServerAutoConfiguration.java index 9b04bc9..1ed62d2 100644 --- a/multitenancy-spring-boot-autoconfigure/src/main/java/org/axonframework/extensions/multitenancy/autoconfig/MultiTenancyAxonServerAutoConfiguration.java +++ b/multitenancy-spring-boot-autoconfigure/src/main/java/org/axonframework/extensions/multitenancy/autoconfig/MultiTenancyAxonServerAutoConfiguration.java @@ -70,7 +70,7 @@ @AutoConfiguration @ConditionalOnClass(AxonServerConfiguration.class) @ConditionalOnProperty(value = {"axon.axonserver.enabled", "axon.multi-tenancy.enabled"}, matchIfMissing = true) -@AutoConfigureAfter(AxonServerAutoConfiguration.class) +@AutoConfigureBefore(AxonServerAutoConfiguration.class) @ComponentScan(excludeFilters = { @ComponentScan.Filter( type = FilterType.REGEX,