Class QueryGatewayConfigurer

java.lang.Object
org.axonframework.messaging.queryhandling.configuration.QueryGatewayConfigurer

public class QueryGatewayConfigurer extends Object
Factory for creating a named QueryGateway component with optional shutdown-tracking decorators.

Each call to MessagingConfigurer.registerQueryGateway(String, Consumer) produces one independently configured QueryGateway instance registered under the given name. The gateway starts from a bare DefaultQueryGateway that shares infrastructure with the main configuration (same QueryBus, MessageTypeResolver, QueryPriorityCalculator, and MessageConverter), and is optionally wrapped in a ShutdownTrackingQueryGateway when shutdown cancellation is configured.

This configurer is not intended to be instantiated directly. Access it via MessagingConfigurer.registerQueryGateway(String, java.util.function.Consumer):


 MessagingConfigurer.create()
     .registerQueryGateway("reporting", g -> g
         .cancellingSubscriptionQueryOnShutdown(Duration.ofSeconds(10))
         .cancellingStreamingQueryOnShutdown(Duration.ofSeconds(5))
     );
 
Since:
5.4.0
Author:
Allard Buijze
  • Constructor Details

  • Method Details

    • withDefaults

      public QueryGatewayConfigurer withDefaults()
      Accepts the default configuration for this gateway without applying any decorators.

      This method is a no-op provided for readability when registering a plain DefaultQueryGateway with no shutdown tracking:

      
       MessagingConfigurer.create()
           .registerQueryGateway("reporting", QueryGatewayConfigurer::withDefaults);
       
      Returns:
      this configurer, unchanged
    • cancellingSubscriptionQueryOnShutdown

      public QueryGatewayConfigurer cancellingSubscriptionQueryOnShutdown()
      Configures all subscription queries dispatched through this gateway to be cancelled immediately when the application shuts down.

      With this option set, callers do not need to wrap subscription query results with QueryShutdownManager.track(org.reactivestreams.Publisher) manually; the gateway handles tracking for every dispatched subscription query automatically.

      Cancellation happens at Phase.OUTBOUND_QUERY_CONNECTORS during application shutdown.

      Returns:
      this configurer, for fluent chaining
    • cancellingSubscriptionQueryOnShutdown

      public QueryGatewayConfigurer cancellingSubscriptionQueryOnShutdown(Duration gracePeriod)
      Configures all subscription queries dispatched through this gateway to be cancelled when the application shuts down, waiting up to the given gracePeriod for them to complete naturally first.

      With this option set, callers do not need to wrap subscription query results with QueryShutdownManager.track(org.reactivestreams.Publisher) manually; the gateway handles tracking for every dispatched subscription query automatically.

      Cancellation happens at Phase.OUTBOUND_QUERY_CONNECTORS during application shutdown.

      Parameters:
      gracePeriod - the maximum time to wait for natural completion before force-closing
      Returns:
      this configurer, for fluent chaining
    • cancellingSubscriptionQueryOnShutdown

      public QueryGatewayConfigurer cancellingSubscriptionQueryOnShutdown(QueryShutdownManager shutdownManager)
      Configures all subscription queries dispatched through this gateway to be tracked by the given shutdownManager, cancelling them according to that manager's policy when the application shuts down.

      Use this overload to share a single QueryShutdownManager between several gateways, or when the manager is also used for call-site tracking through QueryShutdownManager.track(org.reactivestreams.Publisher).

      The given manager's QueryShutdownManager.shutdown() is called at Phase.OUTBOUND_QUERY_CONNECTORS during application shutdown.

      Parameters:
      shutdownManager - the manager to track dispatched subscription queries with
      Returns:
      this configurer, for fluent chaining
    • cancellingStreamingQueryOnShutdown

      public QueryGatewayConfigurer cancellingStreamingQueryOnShutdown()
      Configures all streaming queries dispatched through this gateway to be cancelled immediately when the application shuts down.

      With this option set, callers do not need to wrap streaming query results with QueryShutdownManager.track(org.reactivestreams.Publisher) manually; the gateway handles tracking for every dispatched streaming query automatically.

      Cancellation happens at Phase.OUTBOUND_QUERY_CONNECTORS during application shutdown.

      Returns:
      this configurer, for fluent chaining
    • cancellingStreamingQueryOnShutdown

      public QueryGatewayConfigurer cancellingStreamingQueryOnShutdown(Duration gracePeriod)
      Configures all streaming queries dispatched through this gateway to be cancelled when the application shuts down, waiting up to the given gracePeriod for them to complete naturally first.

      A grace period is typically appropriate here, as streaming queries are finite by nature and expected to complete shortly after shutdown begins.

      With this option set, callers do not need to wrap streaming query results with QueryShutdownManager.track(org.reactivestreams.Publisher) manually; the gateway handles tracking for every dispatched streaming query automatically.

      Cancellation happens at Phase.OUTBOUND_QUERY_CONNECTORS during application shutdown.

      Parameters:
      gracePeriod - the maximum time to wait for natural completion before force-closing
      Returns:
      this configurer, for fluent chaining
    • cancellingStreamingQueryOnShutdown

      public QueryGatewayConfigurer cancellingStreamingQueryOnShutdown(QueryShutdownManager shutdownManager)
      Configures all streaming queries dispatched through this gateway to be tracked by the given shutdownManager, cancelling them according to that manager's policy when the application shuts down.

      Use this overload to share a single QueryShutdownManager between several gateways, or when the manager is also used for call-site tracking through QueryShutdownManager.track(org.reactivestreams.Publisher).

      The given manager's QueryShutdownManager.shutdown() is called at Phase.OUTBOUND_QUERY_CONNECTORS during application shutdown.

      Parameters:
      shutdownManager - the manager to track dispatched streaming queries with
      Returns:
      this configurer, for fluent chaining
    • buildDefinition

      public ComponentDefinition<QueryGateway> buildDefinition()
      Builds a ComponentDefinition for a QueryGateway registered under this configurer's name.

      The produced definition constructs a DefaultQueryGateway from shared infrastructure and wraps it in a ShutdownTrackingQueryGateway if shutdown cancellation was configured. Otherwise, a DefaultQueryGatweay is returned as is. The corresponding managers are then shut down at Phase.OUTBOUND_QUERY_CONNECTORS during application shutdown.

      This method is called by MessagingConfigurer and is not intended to be called directly.

      Returns:
      a ComponentDefinition for the named QueryGateway