模式注册表中的向后兼容性问题和不确定性

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

我有一个用例,其中我有一个JSON,我想生成模式并从JSON中记录并发布记录。我已经配置了值序列化器,并且架构设置是向后兼容的。

[第一个JSON

String json =“ {\ n” +

     "    \"id\": 1,\n" +

     "    \"name\": \"Headphones\",\n" +

     "    \"price\": 1250.0,\n" +

     "    \"tags\": [\"home\", \"green\"]\n" +

     "}\n"
     ;

已注册版本1模式。

Avro控制台使用者中收到的消息。

第二个JSON。

String json =“ {\ n” +

    "    \"id\": 1,\n" +

    "    \"price\": 1250.0,\n" +
    "    \"tags\": [\"home\", \"green\"]\n" +
    "}\n"
    ;

已成功注册架构。已发送消息。

现在尝试发送成功发送的JSON 1

模式3:

String json =“ {\ n” +

    "    \"id\": 1,\n" +
    "    \"name\": \"Headphones\",\n" +

    "    \"tags\": [\"home\", \"green\"]\n" +
    "}\n"
    ;

在这种情况下出现错误。由以下原因引起:io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException:正在注册的架构与早期的架构不兼容。错误代码:409

如何注册从第二个JSON生成的架构,第三个被拒绝了?尽管我没有任何默认键删除字段?是架构注册表始终接受第一个演化? (超过1日的第二个模式)

架构注册表中的架构

版本1架构

{“字段”:[

{

  "doc": "Type inferred from '1'",

  "name": "id",

  "type": "int"

},

{

  "doc": "Type inferred from '\"Headphones\"'",

  "name": "name",

  "type": "string"

},

{

  "doc": "Type inferred from '1250.0'",

  "name": "price",

  "type": "double"

},

{

  "doc": "Type inferred from '[\"home\",\"green\"]'",

  "name": "tags",

  "type": {

    "items": "string",

    "type": "array"

  }

}
],
"name": "myschema",
"type": "record"   }

版本2:

{“字段”:[

{

  "doc": "Type inferred from '1'",

  "name": "id",

  "type": "int"

},

{

  "doc": "Type inferred from '1250.0'",

  "name": "price",

  "type": "double"

},

{

  "doc": "Type inferred from '[\"home\",\"green\"]'",

  "name": "tags",

  "type": {

    "items": "string",

    "type": "array"

  }

}
],
"name": "myschema",
"type": "record"   }
apache-kafka avro kafka-producer-api confluent-schema-registry
1个回答
1
投票

让我们回顾一下向后兼容规则... https://docs.confluent.io/current/schema-registry/avro.html#compatibility-types

首先,默认值不是可传递的,因此版本3仅查看版本2。

向后规则指出,您可以删除字段或添加可选字段(具有默认值的字段)。我假设您的模式生成器工具不知道如何使用可选选项,因此只允许您删除而不添加。

在版本1和版本2之间,您已经删除了有效的名称字段。

在版本2和传入版本3之间,它认为您正在尝试发布一个新的架构,该架构会取消价格(可以的,但可以添加一个必填的名称字段,这是不允许的。

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