-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
In what version(s) of Spring for Apache Kafka are you seeing this issue?
version: 2.8.8
Describe the bug
I am using Avro schema for the kafka messages and the consumer is setup with Spring RetryTopic and DLT.
When consumer encounters an exception during the process of a message and the message goes into the retry topic and then the DLT topic for handling as expected.
When later, it receives a malformed message that cannot be processed correctly, Spring Kafka infinitely retries the message in DLT. Then the application needs to be stopped and the topic cleared before starting again.
The log message is as follows:
DeadLetterPublishingRecovererFactory - Record: topic = request.example, partition = 0, offset = 2, main topic = request.example threw an error at topic request.example and won't be retried. Sending to DLT with name request.example-dlt. {}
org.springframework.kafka.listener.ListenerExecutionFailedException: Listener failed; nested exception is org.springframework.kafka.support.serializer.DeserializationException: failed to deserialize; nested exception is org.apache.kafka.common.errors.SerializationException: Unknown magic byte!
LoggingProducerListener - Exception thrown when sending a message with key='fake-1' and payload='byte[7]' to topic request.example-dlt and partition 0: {}
org.apache.kafka.common.errors.InvalidConfigurationException: Schema being registered is incompatible with an earlier schema for subject "request.example-dlt-value"; error code: 409
Dead-letter publication to request.example-dltfailed for: request.example-0@2 {}
org.springframework.kafka.KafkaException: Send failed; nested exception is org.apache.kafka.common.errors.InvalidConfigurationException: Schema being registered is incompatible with an earlier schema for subject "request.example-dlt-value"; error code: 409
DefaultErrorHandler - Recovery of record (request.example-0@2) failed {}
org.springframework.kafka.KafkaException: Dead-letter publication to request.example-dltfailed for: request.example-0@2
To Reproduce
- Run the new application. It generates the new topics.
- Send a well-formed message where the consumer process it successfully.
- Send a well-formed message where the consumer encounters a Runtime exception. It is retried then enters the DLT successfully.
- Send a malformed message (e.g. regular text, "testing") which is not in Avro format. Spring Kafka encounters an exception. It skips the retry and directly enters DLT. This is repeated until the application is killed.
Expected behavior
Spring Kafka should not retry a message in the same DLT indefinitely.
It would be desirable to configure a special dead letter topic for Deseralization exception, so they can be handled separately then other type of exceptions. If the Avro prevents a topic not tied to a schema, then allowing to configure a handler function would be the next option and ideally the handler would be provided with the binary content of the message, topic name, offset, partition, key, headers and exception information.
Sample
Here's a link to a sample code with instructions to reproduce problem:
https://github.com/clbtrain/spring-kafka-avro-dlt-infinite