Kafka 模式注册表在同一主题中不兼容 [英] Kafka schema registry not compatible in the same topic

查看:30
本文介绍了Kafka 模式注册表在同一主题中不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Kafka schema registry来生产/消费Kafka消息,例如我有两个字段,它们都是字符串类型,伪schema如下:

I'm using Kafka schema registry for producing/consuming Kafka messages, for example I have two fields they are both string type, the pseudo schema as following:

{"name": "test1", "type": "string"}
{"name": "test2", "type": "string"}

但是在发送和消耗一段时间后,我需要修改架构以将第二个字段更改为长类型,然后抛出以下异常:

but after sending and consuming a while, I need modify schema to change the second filed to long type, then it threw the following exception:

Schema being registered is incompatible with an earlier schema; error code: 409

我很困惑,如果架构注册表不能进化架构升级/更改,那我为什么要使用架构注册表,或者说我为什么使用 Avro?

I'm confused, if schema registry can not evolve the schema upgrade/change, then why should I use Schema registry, or say why I use Avro?

推荐答案

不能在 BACKWARD 兼容模式下重命名字段.作为解决方法,您可以更改架构注册表的兼容性规则.

Fields cannot be renamed in BACKWARD compatibility mode. As a workaround you can change the compatibility rules for the schema registry.

根据文档:

模式注册服务器可以强制执行某些兼容性规则在主题中注册新模式时.目前,我们支持以下兼容性规则.

The schema registry server can enforce certain compatibility rules when new schemas are registered in a subject. Currently, we support the following compatibility rules.

向后兼容性(默认): 新架构向后兼容如果它可以用于读取以前所有模式中写入的数据.向后兼容性对于将数据加载到系统中非常有用,例如Hadoop,因为人们总是可以使用最新架构.

Backward compatibility (default): A new schema is backward compatible if it can be used to read the data written in all previous schemas. Backward compatibility is useful for loading data into systems like Hadoop since one can always query data of all versions using the latest schema.

前向兼容性:新架构是前向的如果所有以前的模式都可以读取写入这里的数据,则兼容架构.向前兼容性对于消费类应用程序很有用只能处理特定版本中的数据,而这些数据可能并不总是最新版本.

Forward compatibility: A new schema is forward compatible if all previous schemas can read data written in this schema. Forward compatibility is useful for consumer applications that can only deal with data in a particular version that may not always be the latest version.

完全兼容:新架构完全如果它既向后兼容又向前兼容,则兼容.

Full compatibility: A new schema is fully compatible if it’s both backward and forward compatible.

无兼容性:新架构可以是任何架构,只要它是有效的阿夫罗.

No compatibility: A new schema can be any schema as long as it’s a valid Avro.

compatibility 设置为 NONE 应该可以解决问题.

Setting compatibility to NONE should do the trick.

# Update compatibility requirements globally
$ curl -X PUT -H "Content-Type: application/vnd.schemaregistry.v1+json" \
    --data '{"compatibility": "NONE"}' \
    http://localhost:8081/config

响应应该是

{"compatibility":"NONE"}

<小时>

除非绝对必要,否则我通常不鼓励将兼容性设置为NONE.

这篇关于Kafka 模式注册表在同一主题中不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆