Class FailedRecordProcessor

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.springframework.core.log.LogAccessor logger  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected FailedRecordProcessor​(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,​?>,​java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff)  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void addNotRetryableException​(java.lang.Class<? extends java.lang.Exception> exceptionType)
      Deprecated.
      void addNotRetryableExceptions​(java.lang.Class<? extends java.lang.Exception>... exceptionTypes)
      Add exception types to the default list.
      void clearThreadState()  
      int deliveryAttempt​(TopicPartitionOffset topicPartitionOffset)
      Return the next delivery attempt for the topic/partition/offset.
      protected org.springframework.classify.BinaryExceptionClassifier getClassifier()
      Return the exception classifier.
      protected java.util.function.BiPredicate<org.apache.kafka.clients.consumer.ConsumerRecord<?,​?>,​java.lang.Exception> getSkipPredicate​(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<?,​?>> records, java.lang.Exception thrownException)  
      protected boolean isCommitRecovered()
      Whether the offset for a recovered record should be committed.
      boolean removeNotRetryableException​(java.lang.Class<? extends java.lang.Exception> exceptionType)
      Remove an exception type from the configured list.
      void setBackOffFunction​(java.util.function.BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?,​?>,​java.lang.Exception,​org.springframework.util.backoff.BackOff> backOffFunction)
      Set a function to dynamically determine the BackOff to use, based on the consumer record and/or exception.
      void setClassifications​(java.util.Map<java.lang.Class<? extends java.lang.Throwable>,​java.lang.Boolean> classifications, boolean defaultValue)
      Set an exception classifications to determine whether the exception should cause a retry (until exhaustion) or not.
      void setCommitRecovered​(boolean commitRecovered)
      Set to true to commit the offset for a recovered record.
      void setResetStateOnExceptionChange​(boolean resetStateOnExceptionChange)
      Set to true to reset the retry BackOff if the exception is a different type to the previous failure for the same record.
      void setResetStateOnRecoveryFailure​(boolean resetStateOnRecoveryFailure)
      Set to false to immediately attempt to recover on the next attempt instead of repeating the BackOff cycle when recovery fails.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        protected final org.springframework.core.log.LogAccessor logger
    • Constructor Detail

      • FailedRecordProcessor

        protected FailedRecordProcessor​(@Nullable
                                        java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,​?>,​java.lang.Exception> recoverer,
                                        org.springframework.util.backoff.BackOff backOff)
    • Method Detail

      • getClassifier

        protected org.springframework.classify.BinaryExceptionClassifier getClassifier()
        Return the exception classifier.
        Returns:
        the classifier.
      • setClassifications

        public void setClassifications​(java.util.Map<java.lang.Class<? extends java.lang.Throwable>,​java.lang.Boolean> classifications,
                                       boolean defaultValue)
        Set an exception classifications to determine whether the exception should cause a retry (until exhaustion) or not. If not, we go straight to the recoverer. By default, the following exceptions will not be retried:
        • DeserializationException
        • MessageConversionException
        • MethodArgumentResolutionException
        • NoSuchMethodException
        • ClassCastException
        All others will be retried. When calling this method, the defaults will not be applied.
        Parameters:
        classifications - the classifications.
        defaultValue - whether or not to retry non-matching exceptions.
        See Also:
        BinaryExceptionClassifier(Map, boolean), addNotRetryableExceptions(Class...)
      • isCommitRecovered

        protected boolean isCommitRecovered()
        Whether the offset for a recovered record should be committed.
        Returns:
        true to commit recovered record offsets.
      • setCommitRecovered

        public void setCommitRecovered​(boolean commitRecovered)
        Set to true to commit the offset for a recovered record.
        Parameters:
        commitRecovered - true to commit.
      • setBackOffFunction

        public void setBackOffFunction​(java.util.function.BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?,​?>,​java.lang.Exception,​org.springframework.util.backoff.BackOff> backOffFunction)
        Set a function to dynamically determine the BackOff to use, based on the consumer record and/or exception. If null is returned, the default BackOff will be used.
        Parameters:
        backOffFunction - the function.
        Since:
        2.6
      • setResetStateOnRecoveryFailure

        public void setResetStateOnRecoveryFailure​(boolean resetStateOnRecoveryFailure)
        Set to false to immediately attempt to recover on the next attempt instead of repeating the BackOff cycle when recovery fails.
        Parameters:
        resetStateOnRecoveryFailure - false to retain state.
        Since:
        2.5.5
      • setResetStateOnExceptionChange

        public void setResetStateOnExceptionChange​(boolean resetStateOnExceptionChange)
        Set to true to reset the retry BackOff if the exception is a different type to the previous failure for the same record. The backOffFunction, if provided, will be called to get the BackOff to use for the new exception; otherwise, the configured BackOff will be used.
        Parameters:
        resetStateOnExceptionChange - true to reset.
        Since:
        2.6.3
      • deliveryAttempt

        public int deliveryAttempt​(TopicPartitionOffset topicPartitionOffset)
        Description copied from interface: DeliveryAttemptAware
        Return the next delivery attempt for the topic/partition/offset.
        Specified by:
        deliveryAttempt in interface DeliveryAttemptAware
        Parameters:
        topicPartitionOffset - the topic/partition/offset.
        Returns:
        the next delivery attempt.
      • addNotRetryableExceptions

        @SafeVarargs
        public final void addNotRetryableExceptions​(java.lang.Class<? extends java.lang.Exception>... exceptionTypes)
        Add exception types to the default list. By default, the following exceptions will not be retried: All others will be retried.
        Parameters:
        exceptionTypes - the exception types.
        Since:
        2.6
        See Also:
        removeNotRetryableException(Class), setClassifications(Map, boolean)
      • removeNotRetryableException

        public boolean removeNotRetryableException​(java.lang.Class<? extends java.lang.Exception> exceptionType)
        Remove an exception type from the configured list. By default, the following exceptions will not be retried: All others will be retried.
        Parameters:
        exceptionType - the exception type.
        Returns:
        true if the removal was successful.
        See Also:
        addNotRetryableExceptions(Class...), setClassifications(Map, boolean)
      • getSkipPredicate

        protected java.util.function.BiPredicate<org.apache.kafka.clients.consumer.ConsumerRecord<?,​?>,​java.lang.Exception> getSkipPredicate​(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<?,​?>> records,
                                                                                                                                                         java.lang.Exception thrownException)
      • clearThreadState

        public void clearThreadState()