Enforcing a value schema from the Kafka REST API for producing messages

I’ve got an Avro schema registered to my cluster which works great when using a Kafka producer client. Ideally, I’d like to enforce the same schema when using the REST API to publish messages also. From what I can gather, I’m supposed to use the value_schema_id in the body when sending data via POST:

{
    "value_schema_id": 6,
    "records": [
        {
            "value": {
                "foo": "bar",
                ...
            }
        }
    ]
}

However, no matter what I put as the value_schema_id value, the message is accepted into the topic. Same goes for if I deviate the record structure from the actual schema format, which means I can’t enforce the schema from behind the REST API.

I’ve even tried submitting the entire Avro JSON inline using value_schema and still it accepts anything I put in there as well as the payload.

Can I enforce registered schemas from the Kafka REST API? If so, how?

Thanks

I figured this one out:

You have to set the Content-Type header to application/vnd.kafka.avro.v2+json! Then it all works as expected.

5 Likes