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
    Modifier and Type
    Interface
    Description
    static enum 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    drain(Duration timeout)
    Attempts to acquire all permits up to the specified timeout.
    default void
    release(int amount)
    Deprecated.
    This method is deprecated and will not be called by the Spring Cloud AWS SQS listener anymore.
    void
    Releases the specified amount of permits for processed messages.
    int
    request(int amount)
    Requests a number of permits.
  • Method Details

    • request

      int request(int amount) throws InterruptedException
      Requests a number of permits. Each obtained permit allows the MessageSource 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, BackPressureHandler.ReleaseReason reason)
      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:

      Parameters:
      amount - the amount of permits to release.
      reason - the reason why the permits were released.
    • release

      @Deprecated default void release(int amount)
      Deprecated.
      This method is deprecated and will not be called by the Spring Cloud AWS SQS listener anymore. Implement release(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

      boolean drain(Duration timeout)
      Attempts to acquire all permits up to the specified timeout. If successful, means all permits were returned and thus no activity is left in the MessageSource.
      Parameters:
      timeout - the maximum amount of time to wait for all permits to be released.
      Returns:
      whether all permits were acquired.