Reputation: 1727
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?
Upvotes: 1
Views: 6457
Reputation: 121177
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 asDeadLetterPublishingRecoverer
) will restore the recordvalue()
, in the dead-letter producer record, to the original value that failed to be deserialized. Previously, thevalue()
was null and user code had to decode theDeserializationException
from the message headers. In addition, you can provide multipleKafkaTemplate
s to the publisher; this might be needed, for example, if you want to publish thebyte[]
from aDeserializationException
, as well as values using a different serializer from records that were deserialized successfully. Here is an example of configuring the publisher withKafkaTemplate
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
Upvotes: 1