首页 > 解决方案 > 使用 SpecificAvroSerde 从 kafka 读取事件时出错

问题描述

从 kafka 主题读取事件时出错

'org.apache.kafka.common.errors.SerializationException:为 id 4494 反序列化 Avro 消息时出错原因:org.apache.kafka.common.errors.SerializationException:在查找阅读器架构时找不到写入器架构中指定的类 topLevelRecord特定记录。

final Map<String, String> schemaMap = Collections.singletonMap(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, schemaServerURL);

final SpecificAvroSerde<VertexTransactionRawEventValue> vertexTransactionRawEventValueAvroSerde = new SpecificAvroSerde<>();

vertexTransactionRawEventValueAvroSerde.configure(schemaMap, false);
KStream<String, VertexTransactionRawEventValue> vertexTransactionRawEventValueKStream =
            streamsBuilder.stream(vertexTransactionRawEventTopic,Consumed.with(Serdes.String(), vertexTransactionRawEventValueAvroSerde));

错误信息

但是,当我将事件读取为 GenericRecord 类型而不是 VertexTransactionRawEventValue 时,我能够读取事件。

KStream<String, VertexTransactionRawEventValue> vertexTransactionRawEventValueKStream =
            streamsBuilder.stream(vertexTransactionRawEventTopic);

标签: javaapache-kafkaapache-kafka-streamsavro

解决方案


错误是说topLevelRecord您的类路径中不存在名为的类。

GenericRecord 不会尝试在您的类路径上查找特定的 Avro 编译类以使用


推荐阅读