migrationspring-kafkaspring-retry

Migrating from spring-kafka 2.7.14 to 3.0.1


We are migrating from spring 5 to 6. I am encountering issues with following methods related to spring-kafka.

  1. SetErrorHandler deprecated in favor of CommonErrorHandler -> i replaced this with setCommonErrorHandler(Recoverer,Back off)

  2. factory.setRetryTemplate(neverRetry...) -> removed in favor of CommonErrorHandler. I want to set a "neverRetry" so that recoveryCallback can address the retries.

  3. factory.setRecoveryCallback -> removed in favor of CommonErrorHandler. I want to check the exception thrown and give it to errorhandler only for a specific exception and just log/return in case of all other exceptions.

I am looking for suggestions to handle point #2 and #3 after moving to 3.0.1. How can I set the commonErrorHandler effectively to replicate the same behavior we had when running on 2.7.14.

I replaced SetErrorHandler with setCommonErrorHandler(Recoverer,Back off) but this is not sufficient for our use case. We need to check the type of exception and use error handler only if reception is a specific one. (Which was earlier achieved through recoveryCallback method)


Solution

  • The use of a RetryTemplate has been deprecated for a long time.

    See the DefaultErrorHandler...

    /**
     * Add exception types to the default list. By default, the following exceptions will
     * not be retried:
     * <ul>
     * <li>{@link DeserializationException}</li>
     * <li>{@link MessageConversionException}</li>
     * <li>{@link ConversionException}</li>
     * <li>{@link MethodArgumentResolutionException}</li>
     * <li>{@link NoSuchMethodException}</li>
     * <li>{@link ClassCastException}</li>
     * </ul>
     * All others will be retried, unless {@link #defaultFalse()} has been called.
     * @param exceptionTypes the exception types.
     * @see #removeClassification(Class)
     * @see #setClassifications(Map, boolean)
     */
    public final void addNotRetryableExceptions(Class<? extends Exception>... exceptionTypes) {
    

    Exceptions that are not retryable are sent directly to the recoverer.