Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto start Axon Server tenant components #160

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,37 @@ public void retryDLQ(@RequestParam String tenant, @RequestParam String processin

Only JPA Dead letter queue and In-Memory queues are supported.

#### Deadline manager

As of now, there is no plan to support deadline manager out of the box.
None of deadline manager implementation support multi-tenancy.
See Event scheduler section as alternative.

#### Event scheduler

You can use event scheduler to schedule events for specific tenant.
To do so, you need to inject `EventScheduler` and use it to schedule events.

@Autowired
private EventScheduler eventScheduler;

@EventHandler
public void eventHandler(Event event) {
ScheduledToken token = eventScheduler.schedule(Instant.now().plusDays(10), event);
//example of cancelation
eventScheduler.cancelSchedule(token);
}

If you use scheduler from any message handler, it will automatically pick up tenant from message metadata, you dont need to specify it.
If you wish to use scheduler outside of message handlers, you need to wrap execution into tenant transaction where you specify tenant.

new TenantWrappedTransactionManager(
TenantDescriptor.tenantWithId(tenantName))
.executeInTransaction(() ->
eventScheduler.cancelSchedule(token)
);


### Supported multi-tenant components

Currently, supported multi-tenants components are as follows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -108,17 +108,21 @@ public TenantCommandSegmentFactory tenantAxonServerCommandSegmentFactory(
AxonServerConfiguration axonServerConfig,
AxonServerConnectionManager connectionManager
) {
return tenantDescriptor -> AxonServerCommandBus.builder()
.localSegment(localSegment)
.serializer(messageSerializer)
.routingStrategy(routingStrategy)
.priorityCalculator(priorityCalculator)
.loadFactorProvider(loadFactorProvider)
.targetContextResolver(targetContextResolver)
.axonServerConnectionManager(connectionManager)
.configuration(axonServerConfig)
.defaultContext(tenantDescriptor.tenantId())
.build();
return tenantDescriptor -> {
schananas marked this conversation as resolved.
Show resolved Hide resolved
AxonServerCommandBus commandBus = AxonServerCommandBus.builder()
.localSegment(localSegment)
.serializer(messageSerializer)
.routingStrategy(routingStrategy)
.priorityCalculator(priorityCalculator)
.loadFactorProvider(loadFactorProvider)
.targetContextResolver(targetContextResolver)
.axonServerConnectionManager(connectionManager)
.configuration(axonServerConfig)
.defaultContext(tenantDescriptor.tenantId())
.build();
commandBus.start();
return commandBus;
};
}


Expand Down Expand Up @@ -152,20 +156,23 @@ public TenantQuerySegmentFactory tenantAxonServerQuerySegmentFactory(
new CorrelationDataInterceptor<>(config.correlationDataProviders())
);

return AxonServerQueryBus.builder()
.axonServerConnectionManager(axonServerConnectionManager)
.configuration(axonServerConfig)
.localSegment(simpleQueryBus)
.updateEmitter(
((MultiTenantQueryUpdateEmitter) multiTenantQueryUpdateEmitter)
.getTenant(tenantDescriptor)
)
.messageSerializer(messageSerializer)
.genericSerializer(genericSerializer)
.priorityCalculator(priorityCalculator)
.targetContextResolver(targetContextResolver)
.defaultContext(tenantDescriptor.tenantId())
.build();
AxonServerQueryBus queryBus = AxonServerQueryBus.builder()
.axonServerConnectionManager(axonServerConnectionManager)
.configuration(axonServerConfig)
.localSegment(simpleQueryBus)
.updateEmitter(
((MultiTenantQueryUpdateEmitter) multiTenantQueryUpdateEmitter)
.getTenant(tenantDescriptor)
)
.messageSerializer(messageSerializer)
.genericSerializer(genericSerializer)
.priorityCalculator(priorityCalculator)
.targetContextResolver(targetContextResolver)
.defaultContext(tenantDescriptor.tenantId())
.build();

queryBus.start();
return queryBus;
};
}

Expand Down Expand Up @@ -214,11 +221,15 @@ public TenantEventSchedulerSegmentFactory tenantEventSchedulerSegmentFactory(
AxonServerConnectionManager axonServerConnectionManager,
Serializer serializer
) {
return tenant -> AxonServerEventScheduler.builder()
.connectionManager(axonServerConnectionManager)
.eventSerializer(serializer)
.defaultContext(tenant.tenantId())
.build();
return tenant -> {
AxonServerEventScheduler eventScheduler = AxonServerEventScheduler.builder()
.connectionManager(axonServerConnectionManager)
.eventSerializer(serializer)
.defaultContext(tenant.tenantId())
.build();
eventScheduler.start();
return eventScheduler;
};
}

@Bean
Expand All @@ -233,6 +244,7 @@ public EventProcessorInfoConfiguration processorInfoConfiguration(
c.getComponent(AxonServerConfiguration.class)
);
tenantProvider.subscribe(controlService);
controlService.start();
schananas marked this conversation as resolved.
Show resolved Hide resolved
return controlService;
});
}
Expand Down
2 changes: 1 addition & 1 deletion multitenancy-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<maven-deploy.version>3.1.1</maven-deploy.version>
<maven-gpg.version>3.1.0</maven-gpg.version>
<maven-install.version>3.1.1</maven-install.version>
<maven-javadoc.version>3.6.0</maven-javadoc.version>
<maven-javadoc.version>3.6.2</maven-javadoc.version>
<maven-resources.version>3.3.1</maven-resources.version>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<maven-gpg.version>3.1.0</maven-gpg.version>
<maven-install.version>3.1.1</maven-install.version>
<maven-jar.version>3.3.0</maven-jar.version>
<maven-javadoc.version>3.6.0</maven-javadoc.version>
<maven-javadoc.version>3.6.2</maven-javadoc.version>
<maven-release.version>3.0.1</maven-release.version>
<maven-source.version>3.3.0</maven-source.version>
<maven-surefire.version>3.1.2</maven-surefire.version>
Expand Down
Loading