Interface BackPressureHandler
- All Known Subinterfaces:
BatchAwareBackPressureHandler
- All Known Implementing Classes:
CompositeBackPressureHandler,ConcurrencyLimiterBlockingBackPressureHandler,FullBatchBackPressureHandler,SemaphoreBackPressureHandler,ThroughputBackPressureHandler
public interface BackPressureHandler
Abstraction to handle backpressure within a
PollingMessageSource.
Release methods must be thread-safe so that many messages can be processed asynchronously. Example strategies are
semaphore-based, rate limiter-based, a mix of both, or any other.- Since:
- 3.0
- Author:
- Tomaz Fernandes, Loïc Rouchon
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbooleanAttempts to acquire all permits up to the specified timeout.default voidrelease(int amount) Deprecated.This method is deprecated and will not be called by the Spring Cloud AWS SQS listener anymore.voidrelease(int amount, BackPressureHandler.ReleaseReason reason) Releases the specified amount of permits for processed messages.intrequest(int amount) Requests a number of permits.
-
Method Details
-
request
Requests a number of permits. Each obtained permit allows theMessageSourceto retrieve one message.- 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
Releases 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.
- Parameters:
amount- the amount of permits to release.reason- the reason why the permits were released.
-
release
Deprecated.This method is deprecated and will not be called by the Spring Cloud AWS SQS listener anymore. Implementrelease(int, ReleaseReason)instead.Release the specified amount of permits. Each message that has been processed should release one permit, whether processing was successful or not.- Parameters:
amount- the amount of permits to release.
-
drain
Attempts to acquire all permits up to the specified timeout. If successful, means all permits were returned and thus no activity is left in theMessageSource.- Parameters:
timeout- the maximum amount of time to wait for all permits to be released.- Returns:
- whether all permits were acquired.
-