【发布时间】:2019-08-25 06:52:59
【问题描述】:
好的,考虑到我已经问过一个相关问题,现在我有点沮丧:
Why kafka-avro-console-producer doesn't honour the default value for the field?
如果生产者使用旧架构而没有新字段 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 测试呢?
【问题讨论】:
-
kafka-avro-console-consumer 忽略
--property value.schema选项中指定的架构。它使用消息中指定的模式。事实上,kafka-avro-console-consumer examples 都没有使用该选项。 -
请告诉我们
curl http://localhost:8081/subjects/test-avro-value/versions/1
标签: apache-kafka avro confluent-schema-registry