I have a KafkaListener consuming Avro messages from Kafka. If the logic that processes the consumed message throws an exception the error handler will send the message to a DLT. I want to send that message as a JSON and ignore any schema registry stuff. I'm running into problems because if I try to use a JSON serializer it fails to serialize since it's an Avro object.
error handler
@Bean
public DefaultErrorHandler errorHandler(final KafkaTemplate<String, ?> template) {
DefaultErrorHandler handler =
new DefaultErrorHandler(
new DeadLetterPublishingRecoverer(template), new FixedBackOff(0L, 0L));
handler.addNotRetryableExceptions(
IllegalArgumentException.class, SaveFactFailedException.class);
return handler;
}
Producer Configs
producer:
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: com.amazonaws.services.schemaregistry.serializers.avro.AWSKafkaAvroSerializer
That's the first problem.
The second issue is the original listener and the DLT listener are both using the same Deserializer which is set in the application.yml
. How can I configure different deserializers for each listener?
Consumer Configs
consumer:
enable-auto-commit: false
group-id: mobile-layout-group
key-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
value-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
properties:
spring.deserializer.key.delegate.class: org.apache.kafka.common.serialization.StringDeserializer
spring.deserializer.value.delegate.class: com.amazonaws.services.schemaregistry.deserializers.avro.AWSKafkaAvroDeserializer
auto-offset-reset: earliest