I am using Spring Cloud Stream with Kafka Stream binder. I want to alter the way deserilization exception and transient error are handled.
To handle deserilization exceptions I added
spring.cloud.stream.kafka.streams.binder.deserializationExceptionHandler= sendToDlq
spring.cloud.stream.kafka.streams.bindings.consume-in-0.consumer.dlqName= my-dlq
I saw this in my logs which is good.
default.deserialization.exception.handler = class org.springframework.kafka.streams.RecoveringDeserializationExceptionHandler
To handle Transient error, I referred to this documentation here
@Getter
@EnableConfigurationProperties({MyConfig.class})
@Slf4j
public class AppConfig {
public static class MyStreamsUncaughtExceptionHandler implements StreamsUncaughtExceptionHandler {
@Override
public StreamThreadExceptionResponse handle(Throwable exception) {
log.error("Exception occurred::", exception);
return StreamThreadExceptionResponse.REPLACE_THREAD;
}
}
@Bean
public StreamsBuilderFactoryBeanCustomizer streamsBuilderFactoryBeanCustomizer() {
return factoryBean -> {
log.info("11111111111");
factoryBean.setKafkaStreamsCustomizer(new KafkaStreamsCustomizer() {
@Override
public void customize(KafkaStreams kafkaStreams) {
log.info("222222222");
kafkaStreams.setUncaughtExceptionHandler(new MyStreamsUncaughtExceptionHandler());
}
});
};
}
}
The ERROR thread does not get replaced when a transient error occurs. Also, both the log statements are not executed. log.info("222222222"); & log.info("11111111111"); I am not sure what I am missing.
I saw a similar post here But it did not help my situation.