Apache Avro 别名与模式注册表

问题描述 投票:0回答:1

我正在尝试使用别名重命名文件名并从 avro 模式中生成 java 类。使用新名称生成消息,但我的消费者应用程序在架构中具有旧名称或别名。反序列化消息时出现异常。

生产者模式有:

        {
                            "name": "eventType",
                            "aliases": ["event"], <!-- oldname-->
                            "type": [
                                "null",
                                "string"
                            ]
                        },

消费者模式:

     {
                            "name": "event",
                             "type": [
                                "null",
                                "string"
                            ]
                        },

错误

 Caused by: org.apache.avro.AvroTypeException: Found com.Employee, expecting com.Employee, missing required field event
avro confluent-schema-registry
1个回答
0
投票

数据是用

eventType
生成的。因此,这就是反序列化器将尝试用作生成类型的字段名称的内容。

您需要将

"aliases": ["eventType"]
添加到
"name": "event"
,以便反序列化器在消费者端重用该字段。

© www.soinside.com 2019 - 2024. All rights reserved.