Kafka Schema Registry
Revision | Date | Description |
|---|---|---|
| 24.07.2024 | Init Changelog |
API
Every method described below or other you can find in official documentation: Schema Registry API Reference | Confluent Documentation
Get list of all schema subjects
curl kafka-schema-registry.example.com/subjects
["kafka-schemaregistry-test-values"]
Adding new schema with API
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{ "schema": "{ \"type\": \"record\", \"name\": \"Person\", \"fields\": [ { \"name\": \"firstName\", \"type\": \"string\" }, { \"name\": \"lastName\", \"type\": \"string\" } ]}" }' \
kafka-schema-registry.example.com/subjects/kafka-schemaregistry-test-values/versions
{"id":1}
Get list of all registered versions of schemas (subject)
curl kafka-schema-registry.example.com/subjects/kafka-schemaregistry-test-values/versions/
[1]
Get version of registered schema
curl kafka-schema-registry.example.com/subjects/kafka-schemaregistry-test-values/versions/1
{"subject":"kafka-schemaregistry-test-values","version":1,"id":1,"schema":"{\"type\":\"record\",\"name\":\"Person\",\"fields\":[{\"name\":\"firstName\",\"type\":\"string\"},{\"name\":\"lastName\",\"type\":\"string\"}]}"}%
Demo
In git repository we can find example for Consumer and Producer using Schema Registry and Avro (based on official guide - On-Premises Schema Registry Tutorial | Confluent Documentation).
In demo repository, there is ready to use config for test Kafka cluster (in file java.config) - you need to set USERNAME and PASSWORD + certificates path.
Usage
mvn clean compile package
-- Initialize Producer and sending 10 messages --
mvn exec:java -Dexec.mainClass=io.confluent.examples.clients.basicavro.ProducerExample \
> -Dexec.args="$HOME/kafka-avro-example/examples/clients/avro/java.config"
-- You should see in logs communicate below --
Successfully produced 10 messages to a topic called TOPIC-NAME
-- Initialize Consumer --
mvn exec:java -Dexec.mainClass=io.confluent.examples.clients.basicavro.ConsumerExample \
> -Dexec.args="$HOME/kafka-avro-example/examples/clients/avro/java.config"
-- There should appear lines like below --
key = id0, value = {"id": "id0", "amount": 1000.0}
key = id3, value = {"id": "id3", "amount": 1000.0}
key = id4, value = {"id": "id4", "amount": 1000.0}
key = id6, value = {"id": "id6", "amount": 1000.0}
key = id8, value = {"id": "id8", "amount": 1000.0}
...
We can see all messages also on Kafka UI web panel.

Last modified: 17 February 2025