简体   繁体   English

为什么kafka-avro-console-consumer不显示缺少字段的默认值?

[英]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.

相关问题 带有kafka-avro-console-consumer的LoggingMessageFormatter - LoggingMessageFormatter with kafka-avro-console-consumer Kafka Avro Consumer (kafka-avro-console-consumer) 日志级别 - Kafka Avro Consumer (kafka-avro-console-consumer) Logging Level 使用kafka-avro-console-consumer获取Avro记录为二进制数组 - Get Avro record as binary array with kafka-avro-console-consumer 为什么kafka-avro-console-producer不遵守该字段的默认值? - Why kafka-avro-console-producer doesn't honour the default value for the field? Kafka + Kubernetes + Helm + `/usr/bin/kafka-avro-console-consumer`? - Kafka + Kubernetes + Helm + `/usr/bin/kafka-avro-console-consumer`? 带有kafka-avro-console-consumer的未知魔术字节 - Unknown magic byte with kafka-avro-console-consumer 使用 kafka-avro-console-consumer 使用旧模式使用消息 - Consume a message with an older schema using kafka-avro-console-consumer 在终端中从 Kafka 读取 Avro 消息 - kafka-avro-console-consumer 替代方案 - Read Avro messages from Kafka in terminal - kafka-avro-console-consumer alternative 无法通过 kafka-avro-console-consumer 读取 avro 消息(最终目标是通过 Spark 流读取) - unable to read avro message via kafka-avro-console-consumer (end goal read it via spark streaming) 在 kafka-avro-console-consumer 中检索 Avro 架构时出现错误 40101 - Error 40101 when retrieving Avro schema in kafka-avro-console-consumer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM