Schema being registered is incompatible with an earlier schema

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

最近在研究Kafka Stream,遇到了很多坑,标题就是刚遇到的一个报错,

报错内容:

Caused by: 
org.apache.kafka.common.errors.SerializationException:
	Error registering Avro schema: {"type":"record","name":...

Caused by: 
io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException:
	Schema being registered is incompatible with an earlier schema;
	error code: 409

可能原因及解决方法:

1、key的schema错误的指定到了value的schema上(或者多次注册不同的schema到一个topic的key或value);
解决:
将 isSerdeForRecordKeys 设置为true

        final SpecificAvroSerde<VT> serde = new SpecificAvroSerde<>();
        final Map<String, String> serdeConfig = Collections.singletonMap(
                AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, schemaRegistryUrl);
        serde.configure(serdeConfig, isSerdeForRecordKeys);

然后删除错误的schema:
a、查看所有已注册的schema:

curl -X GET http://localhost:8081/subjects

为了美观可以使用jq命令:

curl -X GET http://localhost:8081/subjects | jq

b、找到你注册错的schema,schema命名格式为${topic}-value(或者${topic}-key),查看其版本信息:

curl -X GET http://localhost:8081/subjects/${topic}-value/versions

c、将错误的schema信息删除掉:

curl -X DELETE http://localhost:8081/subjects/${topic}-value/versions/1

这样再次启动就不会报错了。
更多schema 操作命令见官网:
https://docs.confluent.io/current/schema-registry/docs/using.html#getting-the-top-level-config

2、注册的schema发生了变动,导致新旧schema不兼容;
内容参考:https://blog.csdn.net/lzufeng/article/details/81566766
解决:
使用命令查看schema配置:

	curl -X GET http://localhost:8081/config

如果结果显示 {“compatibility”:“BACKWARD”},则说明兼容模式为向后兼容,如果确定要使用新schema,可以使用以下命令将兼容模式改为NONE():

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

schema 兼容类型(avro.compatibility.level):

1、none :new schema can be any valid Avro schema;
2、backward :new schema can read data produced by latest registered schema;
3、backward_transitive :new schema can read data produced by all previously registered schemas;
4、forward :latest registered schema can read data produced by the new schema;
5、forward_transitive :all previously registered schemas can read data produced by the new schema;
6、full :new schema is backward and forward compatible with latest registered schema;
7、full_transitive :new schema is backward and forward compatible with all previously registered schemas;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值