Class BackPressureHandlerFactories
BackPressureHandlerFactory instances used to apply back pressure strategies in SQS
listener containers.
The factories provided by this class can be passed to ContainerOptions during container configuration.
Example usage:
factory.configure(options -> options.maxConcurrentMessages(100).maxDelayBetweenPolls(Duration.ofSeconds(1))
.maxMessagesPerPoll(8)
.backPressureHandlerFactory(BackPressureHandlerFactories.concurrencyLimiterBackPressureHandler()));
The BackPressureMode setting in ContainerOptions is only used when using
adaptiveThroughputBackPressureHandler(). If you're passing a specific factory such as
concurrencyLimiterBackPressureHandler(), the mode will be ignored.
The following ContainerOptions properties are used by the built-in back pressure handler implementations:
ConcurrencyLimiterBlockingBackPressureHandlermaxConcurrentMessagesmaxMessagesPerPollmaxDelayBetweenPolls
ThroughputBackPressureHandlermaxMessagesPerPoll
FullBatchBackPressureHandlermaxMessagesPerPoll
For advanced scenarios, multiple handlers can be combined using compositeBackPressureHandler(List) or
compositeBackPressureHandler(BackPressureHandlerFactory...).
- Since:
- 4.0.0
- Author:
- Loïc Rouchon, Tomaz Fernandes
-
Method Summary
Modifier and TypeMethodDescriptionstatic BackPressureHandlerFactoryCreates a factory for an adaptiveBackPressureHandler, combining different strategies based on the providedContainerOptionsand its configuredBackPressureMode.static BackPressureHandlerFactorycompositeBackPressureHandler(BackPressureHandlerFactory... backPressureHandlerFactories) Creates a newCompositeBackPressureHandlerfrom the given array ofBackPressureHandlerFactoryinstances.static BackPressureHandlerFactoryCreates a newCompositeBackPressureHandlerfrom the given list ofBackPressureHandlerFactoryinstances.static BackPressureHandlerFactoryCreates a newConcurrencyLimiterBlockingBackPressureHandlerusing the providedContainerOptions.static BackPressureHandlerFactoryCreates a newFullBatchBackPressureHandlerusing the providedContainerOptions.static BackPressureHandlerFactoryDeprecated.static BackPressureHandlerFactoryCreates a newThroughputBackPressureHandlerusing the providedContainerOptions.
-
Method Details
-
adaptiveThroughputBackPressureHandler
Creates a factory for an adaptiveBackPressureHandler, combining different strategies based on the providedContainerOptionsand its configuredBackPressureMode.This factory dynamically builds a composite handler using one or more of the following:
ConcurrencyLimiterBlockingBackPressureHandlerThroughputBackPressureHandlerFullBatchBackPressureHandler
The resulting behavior is similar to the original
SemaphoreBackpressureHandlerin previous versions.This is the only built-in factory that makes use of
BackPressureMode. If you use a specific factory such asconcurrencyLimiterBackPressureHandler()the mode is not consulted.This is the default BackPressureHandlerFactory used by listener containers.
- Returns:
- a
BackPressureHandlerFactoryproducing adaptive handlers.
-
compositeBackPressureHandler
public static BackPressureHandlerFactory compositeBackPressureHandler(BackPressureHandlerFactory... backPressureHandlerFactories) Creates a newCompositeBackPressureHandlerfrom the given array ofBackPressureHandlerFactoryinstances.- Parameters:
backPressureHandlerFactories- the factories to compose.- Returns:
- a
BackPressureHandlerFactoryproducing a composite handler.
-
compositeBackPressureHandler
public static BackPressureHandlerFactory compositeBackPressureHandler(List<BackPressureHandlerFactory> factories) Creates a newCompositeBackPressureHandlerfrom the given list ofBackPressureHandlerFactoryinstances.- Parameters:
factories- the list of factories to compose.- Returns:
- a
BackPressureHandlerFactoryproducing a composite handler.
-
concurrencyLimiterBackPressureHandler
Creates a newConcurrencyLimiterBlockingBackPressureHandlerusing the providedContainerOptions.- Returns:
- a
BackPressureHandlerFactoryproducing a concurrency-limiting handler.
-
throughputBackPressureHandler
Creates a newThroughputBackPressureHandlerusing the providedContainerOptions.- Returns:
- a
BackPressureHandlerFactoryproducing a throughput-adaptive handler.
-
fullBatchBackPressureHandler
Creates a newFullBatchBackPressureHandlerusing the providedContainerOptions.- Returns:
- a
BackPressureHandlerFactoryproducing a full-batch enforcing handler.
-
semaphoreBackPressureHandler
Deprecated.Creates a newSemaphoreBackPressureHandlerinstance based on the providedContainerOptions.- Returns:
- the created SemaphoreBackPressureHandler.
-