Hi,
I’m working through producing avro messages and applying message validation - against schema - at message produce time. But I am seeing an error i don’t really understand.
I’m doing the following.
- Run Confluent locally.
- Create a topic called “flow”.
- Publish a message to that topic, using kafka-avro-console-producer, string serializer for the key and a simple avro schema with 2 fields for the value, (schema below) e.g. abc:{“first”:3, “second”: “foo”}
{ “type”: “record”, “name”: “demoRecord”,
“fields”: [
{ “name”: “first”, “type”: “int” },
{ “name”: “second”, “type”: “string” }
]
}
- confirm schema has been auto-registered in schema registry following message being produced, e.g.
curl --silent -X GET http://localhost:8081/subjects | jq
[
“flow-value”
]
- “Turn on” schema/message validation, e.g.
kafka-configs --bootstrap-server localhost:9092 --alter --entity-type topics --entity-name flow --add-config confluent.value.schema.validation=true
Completed updating config for topic flow.
- Try and publish the same message again, again using an avro console producer. Kafka now errors, with output:
[2023-05-10 22:07:42,769] ERROR Error when sending message to topic flow with key: 3 bytes, value: 10 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback:52)
org.apache.kafka.common.InvalidRecordException: Log record DefaultRecord(offset=0, timestamp=1683752861715, key=3 bytes, value=10 bytes) is rejected by the record interceptor io.confluent.kafka.schemaregistry.validator.RecordSchemaValidator
Is the output telling me the message isn’t valid against the registered schema subject “flow-value”?