Class MultiTenantPersistentStreamEventSourceFactory

java.lang.Object
io.axoniq.framework.messaging.multitenancy.axonserver.eventstreaming.MultiTenantPersistentStreamEventSourceFactory
All Implemented Interfaces:
PersistentStreamEventSourceFactory

@Internal public class MultiTenantPersistentStreamEventSourceFactory extends Object implements PersistentStreamEventSourceFactory
A PersistentStreamEventSourceFactory building a MultiTenantPersistentStreamEventSource, so a configured persistent stream is consumed from every tenant's Axon Server context rather than from one.

Replaces the default factory while multi-tenancy is active, which is all a Spring Boot application needs to make its persistent-stream-backed event processors multi-tenant: streams stay configured under axon.axonserver.persistent-streams exactly as they are without multi-tenancy.

Marked Internal as concrete, internal implementation of the PersistentStreamEventSourceFactory.

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

    • MultiTenantPersistentStreamEventSourceFactory

      public MultiTenantPersistentStreamEventSourceFactory()
  • Method Details

    • build

      public SubscribableEventSource build(String name, io.axoniq.axonserver.connector.event.PersistentStreamProperties properties, Function<String,ScheduledExecutorService> schedulerFactory, int batchSize, Configuration configuration)
      Builds the SubscribableEventSource consuming the persistent stream described by the given parameters, taking the ScheduledExecutorService instances it needs from the given schedulerFactory.

      The supplied Configuration provides access to all registered framework components, such as the AxonServerConnectionManager and EventConverter, so implementations do not need to receive those as constructor arguments.

      A factory is handed a scheduler factory rather than a scheduler, so implementations can create pools under their control. The requested pool name is used to name the pool's threads, so the source a thread belongs to is visible in a thread dump; pass the stream name for a single stream and a name distinguishing them for several.

      For the MultiTenantPersistentStreamEventSourceFactory each tenant's stream gets a ScheduledExecutorService of its own, taken from the scheduler factory the contract supplies, so the configured thread-count keeps meaning "threads for this stream" and a tenant whose stream is retrying cannot occupy the threads the other tenants need. Pools are named after the stream and the tenant they belong to, so a thread dump shows whose stream a thread is working on.

      Specified by:
      build in interface PersistentStreamEventSourceFactory
      Parameters:
      name - the unique stream name on Axon Server
      properties - the persistent stream properties (segment count, sequencing policy, filter, etc.)
      schedulerFactory - the factory creating a ScheduledExecutorService for the pool name given to it
      batchSize - the maximum number of events to deliver per batch
      configuration - the framework configuration from which additional components can be retrieved
      Returns:
      a new SubscribableEventSource consuming the described persistent stream
    • build

      public SubscribableEventSource build(String name, io.axoniq.axonserver.connector.event.PersistentStreamProperties properties, ScheduledExecutorService scheduler, int batchSize, Configuration configuration)
      Always throws, since a single ScheduledExecutorService shared across every tenant would defeat the per-tenant thread isolation this factory exists to provide.
      Specified by:
      build in interface PersistentStreamEventSourceFactory
      Parameters:
      name - the unique stream name on Axon Server
      properties - the persistent stream properties (segment count, sequencing policy, filter, etc.)
      scheduler - the scheduled executor to use for this stream's background tasks
      batchSize - the maximum number of events to deliver per batch
      configuration - the framework configuration from which additional components can be retrieved
      Returns:
      a new SubscribableEventSource consuming the described persistent stream
      Throws:
      AxonConfigurationException - always, directing the caller to the Function-based build overload instead