Class QueryShutdownAutoConfiguration

java.lang.Object
org.axonframework.extension.springboot.autoconfig.QueryShutdownAutoConfiguration

@AutoConfiguration @AutoConfigureAfter(AxonAutoConfiguration.class) public class QueryShutdownAutoConfiguration extends Object
Auto-configuration that integrates QueryShutdownManager beans with Spring's lifecycle.

When at least one QueryShutdownManager bean is present, this configuration registers a SmartLifecycle that calls QueryShutdownManager.shutdown() on all managers during application shutdown.

Running at DEFAULT_PHASE - 1024, the same phase as Spring Boot's web server graceful shutdown, ensures that subscription queries are cancelled at the same moment the web server stops accepting new connections. This prevents a window where new SSE requests could arrive after cancellation but before the web server rejects them, and allows the web server's drain wait to complete quickly because active queries are being closed simultaneously.

This auto-configuration only handles lifecycle management. Gateway-level tracking, where every subscription or streaming query dispatched through a QueryGateway is automatically registered with a manager, requires explicit configuration. Use QueryShutdownManager.track(org.axonframework.messaging.core.MessageStream<T>) at individual call sites, or configure a named gateway with MessagingConfigurer.registerQueryGateway(java.lang.String, java.util.function.Consumer<org.axonframework.messaging.queryhandling.configuration.QueryGatewayConfigurer>) for automatic per-gateway tracking.

Example:


 @Bean
 public QueryShutdownManager queryShutdownManager() {
     return QueryShutdownManager.closeImmediately();
 }
 
Since:
5.4.0
Author:
Allard Buijze
  • Constructor Details

    • QueryShutdownAutoConfiguration

      public QueryShutdownAutoConfiguration()
  • Method Details

    • queryShutdownManagerLifecycle

      @Bean @ConditionalOnBean(QueryShutdownManager.class) public org.springframework.context.SmartLifecycle queryShutdownManagerLifecycle(List<QueryShutdownManager> managers)
      Creates a SmartLifecycle that calls QueryShutdownManager.shutdown() on all registered QueryShutdownManager beans during application shutdown.

      Runs at DEFAULT_PHASE - 1024, the same phase as Spring Boot's web server graceful shutdown, so subscription queries are cancelled at the same moment the web server stops accepting new connections.

      Parameters:
      managers - all QueryShutdownManager beans in the application context
      Returns:
      a lifecycle bean that shuts down all managers at the appropriate phase