Class ThroughputBackPressureHandler
java.lang.Object
io.awspring.cloud.sqs.listener.backpressure.ThroughputBackPressureHandler
- All Implemented Interfaces:
BackPressureHandler,IdentifiableContainerComponent
public class ThroughputBackPressureHandler
extends Object
implements BackPressureHandler, IdentifiableContainerComponent
A non-blocking
BackPressureHandler that dynamically switches between high- and low-throughput modes to
optimize polling behavior based on recent message availability.
Throughput modes
- Low-throughput mode: Only a single batch may be requested at a time. If a batch is already in-flight, zero permits are granted.
- High-throughput mode: Multiple batches may be requested concurrently. All requested permits are granted.
Throughput mode switching: The handler starts in low-throughput mode. It switches to high-throughput mode if messages are returned from a poll, and reverts to low-throughput mode if no messages are returned.
Typically used in conjunction with a concurrency-limiting BackPressureHandler such as
ConcurrencyLimiterBlockingBackPressureHandler.
This handler builds on the original SemaphoreBackPressureHandler, separating specific responsibilities into a more modular form and enabling composition with other handlers as part of an extensible backpressure strategy.
- Since:
- 4.0.0
- Author:
- Loïc Rouchon, Tomaz Fernandes
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface io.awspring.cloud.sqs.listener.backpressure.BackPressureHandler
BackPressureHandler.ReleaseReason -
Method Summary
Modifier and TypeMethodDescriptionbuilder()booleanAttempts to acquire all permits up to the specified timeout.getId()Get the component id.voidrelease(int amount, BackPressureHandler.ReleaseReason reason) Releases the specified amount of permits for processed messages.intrequest(int amount) Requests a number of permits.voidSet the component id.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.awspring.cloud.sqs.listener.backpressure.BackPressureHandler
release
-
Method Details
-
builder
-
setId
Description copied from interface:IdentifiableContainerComponentSet the component id.- Specified by:
setIdin interfaceIdentifiableContainerComponent- Parameters:
id- the id.
-
getId
Description copied from interface:IdentifiableContainerComponentGet the component id.- Specified by:
getIdin interfaceIdentifiableContainerComponent- Returns:
- the id.
-
request
Description copied from interface:BackPressureHandlerRequests a number of permits. Each obtained permit allows theMessageSourceto retrieve one message.- Specified by:
requestin interfaceBackPressureHandler- Parameters:
amount- the amount of permits to request.- Returns:
- the amount of permits obtained.
- Throws:
InterruptedException- if the Thread is interrupted while waiting for permits.
-
release
Description copied from interface:BackPressureHandlerReleases the specified amount of permits for processed messages. Each message that has been processed should release one permit, whether processing was successful or not.This method can be called in the following use cases:
BackPressureHandler.ReleaseReason.LIMITED: all/some permits were not used because another BackPressureHandler has a lower permits limit and the difference in permits needs to be returned.BackPressureHandler.ReleaseReason.NONE_FETCHED: none of the permits were actually used because no messages were retrieved from SQS. Permits need to be returned.BackPressureHandler.ReleaseReason.PARTIAL_FETCH: some of the permits were used (some messages were retrieved from SQS). The unused ones need to be returned. The amount to be returned might be 0, in which case it means all the permits will be used as the same number of messages were fetched from SQS.BackPressureHandler.ReleaseReason.PROCESSED: a message processing finished, successfully or not.
- Specified by:
releasein interfaceBackPressureHandler- Parameters:
amount- the amount of permits to release.reason- the reason why the permits were released.
-
drain
Description copied from interface:BackPressureHandlerAttempts to acquire all permits up to the specified timeout. If successful, means all permits were returned and thus no activity is left in theMessageSource.- Specified by:
drainin interfaceBackPressureHandler- Parameters:
timeout- the maximum amount of time to wait for all permits to be released.- Returns:
- whether all permits were acquired.
-