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