Possible deserialization issue with spring-kafka 3.1.3

45 Views Asked by At

I just upgraded some of my applications from spring-boot 3.2.3 to spring-boot 3.2.4 which updated spring-kafka from 3.1.2 to 3.1.3 and found some of my tests failing.

The issue only occurs when processing events that lead to an deserialization exception. In this case my custom FailedDeserializationFunction is called, however the faulty event seems to be propagated to one of the configured retry-topics and causes an infinite loop.

Downgrading to spring-boot 3.2.3 / spring-kafka 3.1.2 fixes the issue.

Sample project: here

Running the tests with spring-kafka 3.1.3 yields:

 INFO 143594 --- [kafka-dlt] [yListener-0-C-1] c.e.k.FailedDeserializationFunction      : Failed to deserialize event - returning default
 ERROR 143594 --- [kafka-dlt] [yListener-0-C-1] o.s.k.l.DeadLetterPublishingRecoverer    : Dead-letter publication to test-topic-kafka-dlt-retry-0 failed for: test-topic-0@1
    
    org.apache.kafka.common.errors.SerializationException: Can't convert value of class [B to class org.apache.kafka.common.serialization.IntegerSerializer specified in value.serializer
        at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:1003) ~[kafka-clients-3.6.1.jar:na]
        at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:947) ~[kafka-clients-3.6.1.jar:na]
        at org.springframework.kafka.core.DefaultKafkaProducerFactory$CloseSafeProducer.send(DefaultKafkaProducerFactory.java:1050) ~[spring-kafka-3.1.3.jar:3.1.3]

Question: am I doing something wrong or is this a regression?

1

There are 1 best solutions below

1
Artem Bilan On BEST ANSWER

Thank you for the report an great example!

The problem is here:

@Header(name = SerializationUtils.VALUE_DESERIALIZER_EXCEPTION_HEADER, required = false) byte[] deSerializationErrorHeader

Must be a RecordHeader now instead of byte[].

The fix has been done here: https://github.com/spring-projects/spring-kafka/issues/3114