Class MultiTenantAxonServerQueryBusConnector

java.lang.Object
io.axoniq.framework.messaging.multitenancy.axonserver.queryhandling.MultiTenantAxonServerQueryBusConnector
All Implemented Interfaces:
ConnectorLifecycle, MultiTenantAwareComponent, QueryBusConnector, DescribableComponent

@Internal public class MultiTenantAxonServerQueryBusConnector extends Object implements QueryBusConnector, MultiTenantAwareComponent, ConnectorLifecycle
Multi-tenant Axon Server QueryBusConnector.

The connector composes one AxonServerQueryBusConnector per TenantDescriptor, each owning its own Axon Server connection, query handler subscriptions, and in-flight query tracking. Query subscription state and the incoming-query handler are replayed onto newly registered tenants.

Internal, because the connector is wired by AxonServerMultiTenancyConfigurationDefaults and reached through the QueryBusConnector component, never constructed by an application itself.

Since:
5.3.0
Author:
Jan Galinski, Jakob Hatzl
  • Constructor Details

  • Method Details

    • start

      public void start()
      Description copied from interface: ConnectorLifecycle
      Starts the connector.
      Specified by:
      start in interface ConnectorLifecycle
    • query

      public MessageStream<QueryResponseMessage> query(QueryMessage query, @Nullable ProcessingContext context)
      Resolves the connector for the current tenant and subsequently dispatches the given query to it.
      Specified by:
      query in interface QueryBusConnector
      Parameters:
      query - the query message to dispatch
      context - the processing context for the query
      Returns:
      a MessageStream of the responses for the query
      See Also:
    • subscriptionQuery

      public MessageStream<QueryResponseMessage> subscriptionQuery(QueryMessage query, @Nullable ProcessingContext context, int updateBufferSize)
      Resolves the connector for the current tenant and subsequently dispatches the given subscription query to it.
      Specified by:
      subscriptionQuery in interface QueryBusConnector
      Parameters:
      query - the subscription query message to dispatch
      context - the processing context for the query
      updateBufferSize - the size of the buffer used to store updates for the subscription query
      Returns:
      a MessageStream of the responses for the query
      See Also:
    • subscribe

      public CompletableFuture<Void> subscribe(QualifiedName queryName)
      Subscribes to a query on each tenant-specific connector with the given queryName.

      The MultiTenantAxonServerQueryBusConnector keeps track of all known subscriptions and replays them on tenants dynamically added at runtime.

      Specified by:
      subscribe in interface QueryBusConnector
      Parameters:
      queryName - the QualifiedName of the query to subscribe to
      Returns:
      a CompletableFuture that completes successfully when this connector subscribed to the given queryName
    • unsubscribe

      public boolean unsubscribe(QualifiedName queryName)
      Unsubscribes from a query with the given queryName from each tenant-specific connector.
      Specified by:
      unsubscribe in interface QueryBusConnector
      Parameters:
      queryName - the QualifiedName of the query to unsubscribe from
      Returns:
      true if the unsubscription was successful, false otherwise
    • onIncomingQuery

      public void onIncomingQuery(QueryBusConnector.Handler handler)
      Registers a handler that will be called when an incoming query is received.

      The handler is registered for each tenant-specific connection to make sure incoming queries from each tenant trigger the handling.

      Specified by:
      onIncomingQuery in interface QueryBusConnector
      Parameters:
      handler - the QueryBusConnector.Handler responsible for managing incoming queries
    • shutdownDispatching

      public CompletableFuture<Void> shutdownDispatching()
      Description copied from interface: ConnectorLifecycle
      Shuts down the connector gracefully.
      Specified by:
      shutdownDispatching in interface ConnectorLifecycle
      Returns:
      a CompletableFuture that completes when the connector has been shutdown.
    • disconnect

      public CompletableFuture<Void> disconnect()
      Description copied from interface: ConnectorLifecycle
      Disconnects the connector.
      Specified by:
      disconnect in interface ConnectorLifecycle
      Returns:
      a CompletableFuture that completes when the connector has been disconnected.
    • registerTenant

      public Registration registerTenant(TenantDescriptor tenantDescriptor)
      Description copied from interface: MultiTenantAwareComponent
      Registers the given tenantDescriptor as a known tenant with this multi-tenant aware component.

      The caller must retain the returned Registration and cancel it when the tenant is removed, since releasing the component's per-tenant resources rides on that cancellation.

      Specified by:
      registerTenant in interface MultiTenantAwareComponent
      Parameters:
      tenantDescriptor - The TenantDescriptor to register with this component.
      Returns:
      A Registration used to deregister the given tenantDescriptor.
    • registerAndStartTenant

      public Registration registerAndStartTenant(TenantDescriptor tenantDescriptor)
      Description copied from interface: MultiTenantAwareComponent
      Registers the given tenantDescriptor as a known tenant with this multi-tenant aware component. If applicable, this task will construct a tenant segment and start it.
      Specified by:
      registerAndStartTenant in interface MultiTenantAwareComponent
      Parameters:
      tenantDescriptor - The TenantDescriptor to register with this component.
      Returns:
      A Registration used to deregister the given tenantDescriptor.
    • describeTo

      public void describeTo(ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.