Reputation: 746
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?
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:
$ 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?
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?
Upvotes: 1
Views: 1505
Reputation: 191884
Your producer has registered the value.schema
you have specified in the Registry.
There is no way to explicitly define a schema for the consumer using Confluent's CLI applications, as it is retrieved directly from the registry based on the schema ID embedded within the byte array of the payload.
Upvotes: 3