Class ListenerUtils


  • public final class ListenerUtils
    extends java.lang.Object
    Listener utilities.
    Since:
    2.0
    Author:
    Gary Russell, Francois Rosiere
    • Method Detail

      • determineListenerType

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

        @Nullable
        public static DeserializationException getExceptionFromHeader​(org.apache.kafka.clients.consumer.ConsumerRecord<?,​?> record,
                                                                      java.lang.String headerName,
                                                                      org.springframework.core.log.LogAccessor logger)
        Extract a DeserializationException from the supplied header name, if present.
        Parameters:
        record - the consumer record.
        headerName - the header name.
        logger - the logger for logging errors.
        Returns:
        the exception or null.
        Since:
        2.3
      • byteArrayToDeserializationException

        @Nullable
        public static DeserializationException byteArrayToDeserializationException​(org.springframework.core.log.LogAccessor logger,
                                                                                   byte[] value)
        Convert a byte array containing a serialized DeserializationException to the DeserializationException.
        Parameters:
        logger - a log accessor to log errors.
        value - the bytes.
        Returns:
        the exception or null if deserialization fails.
        Since:
        2.8.1
      • 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