Class ListenerUtils


  • public final class ListenerUtils
    extends java.lang.Object
    Listener utilities.
    Since:
    2.0
    • Method Detail

      • determineListenerType

        public static ListenerType determineListenerType​(java.lang.Object listener)
        Determine the type of the listener.
        Parameters:
        listener - the listener.
        Returns:
        the ListenerType.
      • recordToString

        @Deprecated
        public static java.lang.String recordToString​(org.apache.kafka.clients.consumer.ConsumerRecord<?,​?> record)
        Deprecated.
        Return the ConsumerRecord as a String; either toString() or topic-partition@offset.
        Parameters:
        record - the record.
        Returns:
        the rendered record.
        Since:
        2.2.14
        See Also:
        setLogOnlyMetadata(boolean)
      • recordToString

        @Deprecated
        public static java.lang.String recordToString​(org.apache.kafka.clients.consumer.ConsumerRecord<?,​?> record,
                                                      boolean meta)
        Deprecated.
        Return the ConsumerRecord as a String; either toString() or topic-partition@offset.
        Parameters:
        record - the record.
        meta - true to log just the metadata.
        Returns:
        the rendered record.
        Since:
        2.5.4
      • unrecoverableBackOff

        @Deprecated
        public static void unrecoverableBackOff​(org.springframework.util.backoff.BackOff backOff,
                                                java.lang.ThreadLocal<org.springframework.util.backoff.BackOffExecution> executions,
                                                java.lang.ThreadLocal<java.lang.Long> lastIntervals)
        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.
        Since:
        2.3.12
      • unrecoverableBackOff

        public static void unrecoverableBackOff​(org.springframework.util.backoff.BackOff backOff,
                                                java.lang.ThreadLocal<org.springframework.util.backoff.BackOffExecution> executions,
                                                java.lang.ThreadLocal<java.lang.Long> lastIntervals,
                                                MessageListenerContainer container)
                                         throws java.lang.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:
        java.lang.InterruptedException - if the thread is interrupted.
        Since:
        2.7
      • stoppableSleep

        public static void stoppableSleep​(MessageListenerContainer container,
                                          long interval)
                                   throws java.lang.InterruptedException
        Sleep for the desired timeout, as long as the container continues to run.
        Parameters:
        container - the container.
        interval - the timeout.
        Throws:
        java.lang.InterruptedException - if the thread is interrupted.
        Since:
        2.7
      • 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