apache-kafka - 为什么 kafka-avro-console-consumer 不显示缺失字段的默认值?
问题描述
好的,考虑到我已经问过一个相关问题,现在我有点沮丧:
为什么 kafka-avro-console-producer 不遵守该字段的默认值?
如果生产者使用旧模式而没有新字段 f2,则使用新模式的消费者应该接受该字段的默认值,但在 kafka-avro-console-consumer 的情况下并不明显:
$ kafka-avro-console-producer --broker-list localhost:9092 --topic test-avro --property schema.registry.url=http://localhost:8081 --property value.schema='{"type":"record","name":"myrecord1","fields":[{"name":"f1","type":"string"}]}'
{"f1": "value3"}
$ kafka-avro-console-consumer --bootstrap-server localhost:9092 --topic test-avro --property schema.registry.url=http://localhost:8081 --property value.schema='{"type":"record","name":"myrecord1","fields":[{"name":"f1","type":"string"},{"name": "f2", "type": "int", "default": 0}]}'
{"f1":"value3"}
我的意思是,好的,它确实不会因为缺少 f2 字段而引发异常并终止,这没关系,它显示了它收到的实际消息,但它不应该显示而不是显示该消息的表示形式它使用的架构?
这是模式的两个版本:
curl http://localhost:8081/subjects/test-avro-value/versions/1
{"subject":"test-avro-value","version":1,"id":5,"schema":"{\"type\":\"record\",\"name\":\"myrecord1\",\"fields\":[{\"name\":\"f1\",\"type\":\"string\"}]}"}
curl http://localhost:8081/subjects/test-avro-value/versions/2
{"subject":"test-avro-value","version":2,"id":6,"schema":"{\"type\":\"record\",\"name\":\"myrecord1\",\"fields\":[{\"name\":\"f1\",\"type\":\"string\"},{\"name\":\"f2\",\"type\":\"int\",\"default\":0}]}"}
那么,这是否意味着无法使用 kafka-avro-console-consumer 测试这种情况?
解决方案
您的生产者已注册value.schema
您在注册表中指定的内容。
无法使用 Confluent 的消费者应用程序为消费者明确定义模式,因为它是根据嵌入在有效负载的字节数组中的模式 ID 直接从注册表中检索的。
推荐阅读
- reporting-services - 对 SSRS 中的行组和列组字段进行排序
- azure-devops - Azure Devops 项目终结点和 SQL 凭据
- android - RecyclerView 仅在屏幕旋转后显示
- python - 检查列表中的项目是否存在于另一个列表中,然后写入 SQL 表
- powerbi - 具有最大值和最小值的逐行动态条件格式
- r - 多元分析,如何检验两个方程中某个参数是否不同?
- c - 使用 main 函数进行递归
- r - 强制字符变量长度相同
- mysql - 是否有任何插件/组件可以让我在启动时为 aerospike 填充数据,就像 liquibase 对 mysql 所做的那样?
- google-api - 从学生帐户获取教师信息时无法获取电子邮件地址(OAuth 范围为电子邮件开启)