Class QueryGatewayConfigurer
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 Summary
ConstructorsConstructorDescriptionQueryGatewayConfigurer(String name) Creates a newQueryGatewayConfigurerthat will register the gateway under the givenname. -
Method Summary
Modifier and TypeMethodDescriptionBuilds aComponentDefinitionfor aQueryGatewayregistered under this configurer's name.Configures all streaming queries dispatched through this gateway to be cancelled immediately when the application shuts down.cancellingStreamingQueryOnShutdown(Duration gracePeriod) Configures all streaming queries dispatched through this gateway to be cancelled when the application shuts down, waiting up to the givengracePeriodfor them to complete naturally first.cancellingStreamingQueryOnShutdown(QueryShutdownManager shutdownManager) Configures all streaming queries dispatched through this gateway to be tracked by the givenshutdownManager, cancelling them according to that manager's policy when the application shuts down.Configures all subscription queries dispatched through this gateway to be cancelled immediately when the application shuts down.cancellingSubscriptionQueryOnShutdown(Duration gracePeriod) Configures all subscription queries dispatched through this gateway to be cancelled when the application shuts down, waiting up to the givengracePeriodfor them to complete naturally first.cancellingSubscriptionQueryOnShutdown(QueryShutdownManager shutdownManager) Configures all subscription queries dispatched through this gateway to be tracked by the givenshutdownManager, cancelling them according to that manager's policy when the application shuts down.Accepts the default configuration for this gateway without applying any decorators.
-
Constructor Details
-
QueryGatewayConfigurer
Creates a newQueryGatewayConfigurerthat will register the gateway under the givenname.This constructor is intended for use by
MessagingConfigureronly. Users should access this configurer viaMessagingConfigurer.registerQueryGateway(String, java.util.function.Consumer).- Parameters:
name- the name under which the producedQueryGatewayis registered
-
-
Method Details
-
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
DefaultQueryGatewaywith no shutdown tracking:MessagingConfigurer.create() .registerQueryGateway("reporting", QueryGatewayConfigurer::withDefaults);- Returns:
- this configurer, unchanged
-
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_CONNECTORSduring application shutdown.- Returns:
- this configurer, for fluent chaining
-
cancellingSubscriptionQueryOnShutdown
Configures all subscription queries dispatched through this gateway to be cancelled when the application shuts down, waiting up to the givengracePeriodfor 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_CONNECTORSduring 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 givenshutdownManager, cancelling them according to that manager's policy when the application shuts down.Use this overload to share a single
QueryShutdownManagerbetween several gateways, or when the manager is also used for call-site tracking throughQueryShutdownManager.track(org.reactivestreams.Publisher).The given manager's
QueryShutdownManager.shutdown()is called atPhase.OUTBOUND_QUERY_CONNECTORSduring application shutdown.- Parameters:
shutdownManager- the manager to track dispatched subscription queries with- Returns:
- this configurer, for fluent chaining
-
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_CONNECTORSduring application shutdown.- Returns:
- this configurer, for fluent chaining
-
cancellingStreamingQueryOnShutdown
Configures all streaming queries dispatched through this gateway to be cancelled when the application shuts down, waiting up to the givengracePeriodfor 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_CONNECTORSduring 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 givenshutdownManager, cancelling them according to that manager's policy when the application shuts down.Use this overload to share a single
QueryShutdownManagerbetween several gateways, or when the manager is also used for call-site tracking throughQueryShutdownManager.track(org.reactivestreams.Publisher).The given manager's
QueryShutdownManager.shutdown()is called atPhase.OUTBOUND_QUERY_CONNECTORSduring application shutdown.- Parameters:
shutdownManager- the manager to track dispatched streaming queries with- Returns:
- this configurer, for fluent chaining
-
buildDefinition
Builds aComponentDefinitionfor aQueryGatewayregistered under this configurer's name.The produced definition constructs a
DefaultQueryGatewayfrom shared infrastructure and wraps it in aShutdownTrackingQueryGatewayif shutdown cancellation was configured. Otherwise, aDefaultQueryGatweayis returned as is. The corresponding managers are then shut down atPhase.OUTBOUND_QUERY_CONNECTORSduring application shutdown.This method is called by
MessagingConfigurerand is not intended to be called directly.- Returns:
- a
ComponentDefinitionfor the namedQueryGateway
-