Handle Kafka exceptions like Cluster Authorised Exception such that steams client is not shutdown

Handling Kafka exceptions:

I have used the below handler to handle explicitly steams exception and replace the thread instead of shutdown the client.

//code snippet
public static class StreamsCustomUncaughtExceptionHandler implements StreamsUncaughtExceptionHandler {

        @Override
        public StreamThreadExceptionResponse handle(Throwable exception) {
            log.error("Error message in StreamsCustomUncaughtExceptionHandler {}", exception.getMessage());
            if (exception instanceof StreamsException) {
                Throwable originalException = exception.getCause();
                if (originalException.getMessage().equals("Retryable transient error")) {
                    return StreamThreadExceptionResponse.REPLACE_THREAD;
                }
                log.error("Error message instance of StreamsException {}", exception.getMessage());

            }
            return StreamThreadExceptionResponse.SHUTDOWN_CLIENT;
        }
    }```


Could someone suggest whether SHUTDOWN_KAFKA_STREAMS_CLIENT is valid option to handle the Kafka Exceptions like ClusterAuthorisationException from the spring boot code??

Hi @Snehalathasri ,

While there are no hard and fast rules on this question, I’d say it’s a reasonable approach as an authorization exception seems unlikely to be transient; you’d want to shut down the Kafka Streams application to investigate the issue.

HTH,
Bill

1 Like