Class AxonServerTenantProvider

java.lang.Object
io.axoniq.framework.messaging.multitenancy.axonserver.api.AxonServerTenantProvider
All Implemented Interfaces:
TenantDescriptors, TenantProvider

@Internal public class AxonServerTenantProvider extends Object implements TenantProvider
Axon Server implementation of the 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 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 Server
      tenantConnectPredicate - the predicate to filter which contexts become tenants
  • Method Details

    • start

      public CompletableFuture<Void> start()
      Start this TenantProvider, by adding all tenants and subscribing to the AxonServerConnectionManager for context updates.
      Returns:
      a CompletableFuture that completes when the provider has started
    • tenants

      public List<TenantDescriptor> tenants()
      Description copied from interface: TenantProvider
      Get the list of registered tenants with this provided.
      Specified by:
      tenants in interface TenantDescriptors
      Specified by:
      tenants in interface TenantProvider
      Returns:
      The list of registered tenants.
    • isKnown

      public boolean isKnown(TenantDescriptor tenant)
      Description copied from interface: TenantDescriptors
      Indicates whether the given tenant is one of the tenants of 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:
      isKnown in interface TenantDescriptors
      Parameters:
      tenant - the tenant to check
      Returns:
      true when the given tenant is known
    • addTenant

      public void addTenant(TenantDescriptor tenantDescriptor)
      Adds the given tenantDescriptor as a known tenant, registering and starting every subscribed MultiTenantAwareComponent for it. A tenant that is already known is ignored, so its components are never registered twice.
      Parameters:
      tenantDescriptor - the TenantDescriptor representing the tenant to be added
    • removeTenant

      public void removeTenant(TenantDescriptor tenantDescriptor)
      Removes a tenant from the system.

      This method checks if the provided TenantDescriptor is in the set of known tenants. If it is, the method removes the tenant and cancels all its registrations. MultiTenantAwareComponents are then unregistered in reverse order of their registration. It then disconnects the tenant from the Axon Server.

      Parameters:
      tenantDescriptor - the TenantDescriptor representing the tenant to be removed
    • subscribe

      public Registration subscribe(MultiTenantAwareComponent component)
      Description copied from interface: TenantProvider
      Subscribes the given component with 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 Registration unsubscribes the component and cancels the tenant registrations made on its behalf, giving the component the opportunity to release its per-tenant resources.

      Specified by:
      subscribe in interface TenantProvider
      Parameters:
      component - to be subscribed MultiTenantAwareComponent for tenant changes.
      Returns:
      the registration for the given component.
    • shutdown

      public CompletableFuture<Void> 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 CompletableFuture that completes when the provider has shut down