【发布时间】:2023-01-10 22:54:24
【问题描述】:
您好,我正在使用 Apache Kafka 来消费来自另一个应用程序的消息。当消息反序列化或转换出现问题时,我想处理错误场景。我正在使用 Avro 架构来接收对象。
我实施了以下
@Configuration
@Slf4j
public class ConsumerConfig {
@Bean
ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(
ConcurrentKafkaListenerContainerFactoryConfigurer configurer,
ConsumerFactory<Object, Object> kafkaConsumerFactory) {
ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
configurer.configure(factory, kafkaConsumerFactory);
factory.setErrorHandler(((exception, data) -> {
log.error("Error in process with Exception {} and the record is {}", exception, data);
}));
return factory;
}
}
但是如果我传递不同对象类型的消息,上面的代码不会处理它。我试图传递一个字符串,它抛出了错误但没有进入 Error Hdnaler。
org.apache.kafka.common.errors.InvalidConfigurationException: Schema being registered is incompatible with an earlier schema for subject "taas.cacib.lscsad-dev.queue.wwfdbtemp.Avros-value" io.confluent.kafka.schemaregistry.rest.exceptions.RestIncompatibleSchemaException: Schema being registered is incompatible with an earlier schema for subject "taas.cacib.lscsad-dev.queue.wwfdbtemp.Avros-value"
【问题讨论】:
标签: java spring-boot apache-kafka spring-kafka