【发布时间】:2019-12-26 11:40:08
【问题描述】:
我希望有一个使用 Spring Cloud Stream 的通用使用者,我不需要在编译时专门指定 Avro 消息的架构。由于消息中包含模式 id,因此应该可以使用模式 id 将其反序列化为对象或通用记录(这可以在 Spring Cloud Stream 框架之外轻松完成)。为此,我尝试使用与我们使用具有特定记录的 Spring Cloud Stream 应用程序相同的方法。显然,这种方法不起作用,因为我需要在消费时指定记录类型。它抛出以下异常:
Caused by: org.apache.kafka.common.errors.SerializationException: Could not find class com.example.avro.model.InputModel specified in writer's schema whilst finding reader's schema for a SpecificRecord.
我想知道是否有一种方法可以在编译时不知道架构(和消息类型)的情况下使用来自主题的消息。
消费者的sn-p:
@StreamListener(Processor.INPUT)
public void handleMessage(Object message) {
...
}
P.S:我使用io.confluent.kafka.serializers.KafkaAvroDeserializer 作为值反序列化器。
【问题讨论】:
标签: apache-kafka avro spring-kafka spring-cloud-stream confluent-schema-registry