Class ListenerUtils

java.lang.Object
org.springframework.kafka.listener.ListenerUtils

public final class ListenerUtils extends Object
Listener utilities.
Since:
2.0
  • Method Details

    • determineListenerType

      public static ListenerType determineListenerType(Object listener)
      Determine the type of the listener.
      Parameters:
      listener - the listener.
      Returns:
      the ListenerType.
    • unrecoverableBackOff

      @Deprecated(since="3.1", forRemoval=true) public static void unrecoverableBackOff(org.springframework.util.backoff.BackOff backOff, ThreadLocal<org.springframework.util.backoff.BackOffExecution> executions, ThreadLocal<Long> lastIntervals, MessageListenerContainer container) throws InterruptedException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sleep according to the BackOff; when the BackOffExecution returns BackOffExecution.STOP sleep for the previous backOff.
      Parameters:
      backOff - the BackOff to create a new BackOffExecution.
      executions - a thread local containing the BackOffExecution for this thread.
      lastIntervals - a thread local containing the previous BackOff interval for this thread.
      container - the container or parent container.
      Throws:
      InterruptedException - if the thread is interrupted.
      Since:
      2.7
    • unrecoverableBackOff

      public static void unrecoverableBackOff(org.springframework.util.backoff.BackOff backOff, Map<Thread,org.springframework.util.backoff.BackOffExecution> executions, Map<Thread,Long> lastIntervals, MessageListenerContainer container) throws InterruptedException
      Sleep according to the BackOff; when the BackOffExecution returns BackOffExecution.STOP sleep for the previous backOff.
      Parameters:
      backOff - the BackOff to create a new BackOffExecution.
      executions - a thread local containing the BackOffExecution for this thread.
      lastIntervals - a thread local containing the previous BackOff interval for this thread.
      container - the container or parent container.
      Throws:
      InterruptedException - if the thread is interrupted.
      Since:
      3.1
    • stoppableSleep

      public static void stoppableSleep(MessageListenerContainer container, long interval) throws InterruptedException
      Sleep for the desired timeout, as long as the container continues to run.
      Parameters:
      container - the container.
      interval - the timeout.
      Throws:
      InterruptedException - if the thread is interrupted.
      Since:
      2.7
    • conditionalSleep

      public static void conditionalSleep(Supplier<Boolean> shouldSleepCondition, long interval) throws InterruptedException
      Sleep for the desired timeout, as long as shouldSleepCondition supplies true.
      Parameters:
      shouldSleepCondition - to.
      interval - the timeout.
      Throws:
      InterruptedException - if the thread is interrupted.
      Since:
      3.0.9
    • createOffsetAndMetadata

      public static org.apache.kafka.clients.consumer.OffsetAndMetadata createOffsetAndMetadata(MessageListenerContainer container, long offset)
      Create a new OffsetAndMetadata using the given container and offset.
      Parameters:
      container - a container.
      offset - an offset.
      Returns:
      an offset and metadata.
      Since:
      2.8.6