Class AxonServerTenantProvider
- All Implemented Interfaces:
TenantDescriptors,TenantProvider
TenantProvider. Uses Axon Server's multi-context support to construct
tenant-specific segments of all MultiTenantAwareComponents.
This provider can:
- Discover tenants from predefined context names
- Dynamically discover tenants via Axon Server's Admin API
- Subscribe to context updates to add/remove tenants at runtime
This class is Spring-agnostic and can be used with any framework that uses Axon Server.
Lifecycle management (start/shutdown) is handled through the configuration API via
MessagingConfigurationDefaults.
- Since:
- 4.6.0
- Author:
- Stefan Dragisic, Theo Emanuelsson
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAxonServerTenantProvider(AxonServerConnectionManager axonServerConnectionManager, TenantConnectPredicate tenantConnectPredicate) Constructs an AxonServerTenantProvider with the given connection manager and tenant connect predicate. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTenant(TenantDescriptor tenantDescriptor) Adds the giventenantDescriptoras a known tenant, registering and starting every subscribedMultiTenantAwareComponentfor it.booleanisKnown(TenantDescriptor tenant) Indicates whether the giventenantis one of thetenantsof this application.voidremoveTenant(TenantDescriptor tenantDescriptor) Removes a tenant from the system.shutdown()Shuts down the AxonServerTenantProvider by deregistering all subscribed components.start()Start thisTenantProvider, by adding all tenants and subscribing to theAxonServerConnectionManagerfor context updates.subscribe(MultiTenantAwareComponent component) Subscribes the givencomponentwith this provider.tenants()Get the list of registeredtenantswith this provided.
-
Constructor Details
-
AxonServerTenantProvider
public AxonServerTenantProvider(AxonServerConnectionManager axonServerConnectionManager, TenantConnectPredicate tenantConnectPredicate) Constructs an AxonServerTenantProvider with the given connection manager and tenant connect predicate.- Parameters:
axonServerConnectionManager- the connection manager for Axon ServertenantConnectPredicate- the predicate to filter which contexts become tenants
-
-
Method Details
-
start
Start thisTenantProvider, by adding all tenants and subscribing to theAxonServerConnectionManagerfor context updates.- Returns:
- a
CompletableFuturethat completes when the provider has started
-
tenants
Description copied from interface:TenantProviderGet the list of registeredtenantswith this provided.- Specified by:
tenantsin interfaceTenantDescriptors- Specified by:
tenantsin interfaceTenantProvider- Returns:
- The list of registered
tenants.
-
isKnown
Description copied from interface:TenantDescriptorsIndicates whether the giventenantis one of thetenantsof this application.Answered on every message that carries a tenant, so an implementation backed by a set should override this to test membership directly rather than through the list
TenantDescriptors.tenants()builds.- Specified by:
isKnownin interfaceTenantDescriptors- Parameters:
tenant- the tenant to check- Returns:
truewhen the giventenantis known
-
addTenant
Adds the giventenantDescriptoras a known tenant, registering and starting every subscribedMultiTenantAwareComponentfor it. A tenant that is already known is ignored, so its components are never registered twice.Adding a tenant is all or nothing. When a component fails to register the tenant, the registrations made by the components before it are cancelled in reverse order and the failure is rethrown as is. The tenant becomes known, through
isKnown(TenantDescriptor)andtenants(), when its registration starts, so components that are already live can route its messages. It is withdrawn again if a component fails.What a rollback cannot undo is described on
MultiTenantAwareComponent.When a registration throws an exception during a runtime context update, it is logged and the tenant stays unknown (an
Errorpropagates). The tenant is not retried, since Axon Server sends the creation update of a context only once. Atstart(), a failing initial tenant fails the start.- Parameters:
tenantDescriptor- theTenantDescriptorrepresenting the tenant to be added
-
removeTenant
Removes a tenant from the system.This method checks if the provided
TenantDescriptoris in the set of known tenants. If it is, the method removes the tenant and cancels all its registrations.MultiTenantAwareComponentsare then unregistered in reverse order of their registration. It then disconnects the tenant from the Axon Server.- Parameters:
tenantDescriptor- theTenantDescriptorrepresenting the tenant to be removed
-
subscribe
Subscribes the givencomponentwith this provider.Tenants known to this provider are replayed to the component on subscription, and tenants added or removed afterwards reach the component through its registration hooks. Cancelling the returned
Registrationunsubscribes the component and cancels the tenant registrations made on its behalf, giving the component the opportunity to release its per-tenant resources.Subscribing is all or nothing. When the component fails to register one of the known tenants, the registrations already made for it are cancelled in reverse order, the failure is rethrown as is, and the component is not subscribed. Registrations of an earlier, successful subscription of the same component are left untouched.
What a rollback cannot undo is described on
MultiTenantAwareComponent.- Specified by:
subscribein interfaceTenantProvider- Parameters:
component- to be subscribedMultiTenantAwareComponentfor tenant changes.- Returns:
- the registration for the given component.
-
shutdown
Shuts down the AxonServerTenantProvider by deregistering all subscribed components.Every tenant registration of every subscribed component is cancelled in reverse registration order, so last-registered components are deregistered first and get the opportunity to perform any necessary cleanup.
- Returns:
- a
CompletableFuturethat completes when the provider has shut down
-