I read a lot of documentation and a lot of issues on github of spring-kafka and still didn't get how to make spring DeadLetterRecovererFactory use my custom DeadLetterRecoverer.
Long story short - I want to modify the record before sending it do DLT.(But only before sending to DLT, not between retries).
In documentation of spring-kafka DeadLetterPublishingRecoverer is said - "createProducerRecord(org.apache.kafka.clients.consumer.ConsumerRecord record, org.apache.kafka.common.TopicPartition topicPartition, org.apache.kafka.common.header.internals.RecordHeaders headers) Subclasses can override this method to customize the producer record to send to the DLQ."
So, here I'm creating my custom recoverer.
And injecting it into DefaultErrorHandler
.
But this solution never works. The method createProducerRecord from MyDeadLetterRecoverer wasn't never called. Have no idea how to make this works.
But also later I found interesting comment
Did I missed something or is it Spring really don't allow DeadLetterRecoveryFactory to create an instances of subclasses? Why then they wrote this in their documentation?
Also I tried to implement ProducerInterceptor but this not exactly what I want because in this case I'm losing the spring retryable logic