[英]Why kafka-avro-console-consumer doesn't display the default value for the missing field?
OK, now I am a bit frustrated considering the fact that I already asked a related question: 好的,现在考虑到我已经问过一个相关的问题,我有点沮丧:
Why kafka-avro-console-producer doesn't honour the default value for the field? 为什么kafka-avro-console-producer不遵守该字段的默认值?
If producer uses the old schema without the new field f2, consumer that uses new schema should accept the default for that field, but that is not obvious in case of kafka-avro-console-consumer: 如果生产者使用没有新字段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"}
I mean, OK, it really does not throw an exception and terminate due to a missing f2 field, that is OK, and it shows the actual message that it received, but should it not display instead of that the representation of that message according to the schema it uses? 我的意思是,确定,它确实不会引发异常并由于缺少f2字段而终止,这是确定的,并且它显示了收到的实际消息,但是应该根据消息的显示而不是显示它使用的架构?
Here are both versions of the schema: 这是模式的两个版本:
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}]}"}
So, does it mean that such scenario cannot be tested with kafka-avro-console-consumer? 那么,这是否意味着不能用kafka-avro-console-consumer测试这种情况?
Your producer has registered the value.schema
you have specified in the Registry. 您的生产者已经注册了您在注册表中指定的
value.schema
。
There is no way to explictly define a schema for the consumer using Confluent's consumer applications, as it is retreived directly from the registry based on the schema ID embedded within the byte array of the payload. 无法使用Confluent的使用者应用程序为使用者明确定义一个架构,因为它是根据嵌入在有效负载字节数组中的架构ID直接从注册表中检索的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.