schema-registry

Confluent Schema Registry 管理

补充说明

Schema Registry 为 Kafka 消息提供 Avro/Protobuf/JSON Schema 的集中存储和兼容性检查。它用 REST API 管理 subject、版本和兼容策略,元数据存在 Kafka 内部 topic。

常用示例

curl -s http://schema-registry:8081/subjects
curl -s http://schema-registry:8081/subjects/app-value/versions
curl -s http://schema-registry:8081/subjects/app-value/versions/latest
curl -s http://schema-registry:8081/schemas/ids/1
curl -s http://schema-registry:8081/config

注册 schema:

curl -X POST http://schema-registry:8081/subjects/app-value/versions \
  -H 'Content-Type: application/vnd.schemaregistry.v1+json' \
  -d '{"schema":"{\"type\":\"record\",\"name\":\"App\",\"fields\":[{\"name\":\"id\",\"type\":\"int\"}]}"}'

兼容性配置

curl -X PUT http://schema-registry:8081/config/app-value \
  -H 'Content-Type: application/vnd.schemaregistry.v1+json' \
  -d '{"compatibility":"BACKWARD"}'

常见模式:BACKWARD、FORWARD、FULL、NONE。

易错点与排错

相关命令

读完自测

合上页面,先回答,再展开对照。

  1. 新 schema 注册被拒绝,先看什么?
  2. 删除 subject 后为什么还能查到?
  3. 多实例部署 Schema Registry 的关键前提是什么?
答案
  1. 该 subject 的兼容模式,确认变更是否兼容。
  2. 默认是软删除,彻底删除需要 ?permanent=true,且不可恢复。
  3. 共享同一 Kafka 集群和配置,否则 schema ID 会不一致。