0
votes

I'm using spring-kafka - 2.2.7.RELEASE and trying to understand how can i configure ErrorHandlingDeserializer2 to handle exceptions during deserialization and logs/send them DLT. I'm setting my consumer configs as per the below documentation https://docs.spring.io/spring-kafka/docs/2.2.0.RELEASE/reference/html/_reference.html#error-handling-deserializer.

Here my question is, how do we grab the exception and the consumer record which is failed during deserialization?

1

1 Answers

1
votes

Consider to upgrade to Spring for Apache Kafka 2.3.1.

Here is a Doc how to do your requirement: https://docs.spring.io/spring-kafka/docs/2.3.0.RELEASE/reference/html/#dead-letters

Starting with version 2.3, when used in conjunction with an ErrorHandlingDeserializer2, the publisher (read as DeadLetterPublishingRecoverer) will restore the record value(), in the dead-letter producer record, to the original value that failed to be deserialized. Previously, the value() was null and user code had to decode the DeserializationException from the message headers. In addition, you can provide multiple KafkaTemplate s to the publisher; this might be needed, for example, if you want to publish the byte[] from a DeserializationException, as well as values using a different serializer from records that were deserialized successfully. Here is an example of configuring the publisher with KafkaTemplate s that use a String and byte[] serializer:

So, I believe this doc even gives you a clue how to proceed in the version 2.2.x.

By the way we always recommend to upgrade at least to the latest point release in the generation. Currently that one is 2.2.10: https://spring.io/projects/spring-kafka#learn