Package io.awspring.cloud.sqs.listener
Interface BackPressureHandler
- All Known Subinterfaces:
BatchAwareBackPressureHandler
- All Known Implementing Classes:
SemaphoreBackPressureHandler
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
-
Method Summary
-
Method Details
-
request
Request a number of permits. Each obtained permit allows theMessageSource
to 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
void release(int amount) 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.
-