# Kafka JSON反序列化因未配置模式注册表而失败，报错'未知模式ID'

- **ID:** `data/kafka-json-deserialization-with-schema-registry`
- **领域:** data
- **类别:** config_error
- **错误码:** `KAFKA-ERR-100`
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

Kafka生产者启用了模式注册表写入JSON数据，但消费者未配置模式注册表，或者模式ID不在注册表中。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Confluent Platform 7.4 | active | — | — |
| kafka-python 2.0.2 | active | — | — |
| Apache Kafka 3.5 | active | — | — |

## 解决方案

1. ```
   配置消费者使用相同的模式注册表URL：在消费者属性中添加'schema.registry.url=http://localhost:8081'。
   ```
2. ```
   如果模式注册表不可用，使用忽略模式ID的自定义反序列化器：使用kafka.deserializers.string_deserializer处理原始JSON。
   ```

## 无效尝试

- **Disabling schema registry on the producer side** — Producer may have already written messages with schema IDs; disabling registry only affects new messages, not existing ones. (80% 失败率)
- **Manually editing the Kafka topic to remove schema IDs from message headers** — Editing message headers is complex and risky; schema IDs are embedded in the message payload, not just headers. (90% 失败率)
