Confluent Schema Registry
repository·master·Indexed 25 days ago
https://github.com/confluentinc/schema-registryA centralized service for managing Avro, JSON Schema, and Protobuf schemas in Kafka ecosystems. It provides a RESTful API for schema lifecycle management, versioning, and compatibility enforcement, along with serializers for Apache Kafka clients. Includes CLI tools for producing and consuming Avro, JSON Schema, and Protobuf messages, as well as JMH microbenchmarks for serialization performance.
What's inside Confluent Schema Registry
- Confluent Schema Registry provides a RESTful serving layer for metadata, allowing you to store and retrieve Avro®, JSON Schema, and Protobuf schemas. It maintains a versioned history of schemas based on subject name strategies and enforces compatibility settings to allow for safe schema evolution. It also provides serializers that integrate with Apache Kafka® clients to handle schema storage and retrieval for Kafka messages.
Run Schema Registry locally for development
masterTo run an instance of Schema Registry against a local Kafka cluster using the default configuration, use the following Maven command:
mvn exec:java -pl :kafka-schema-registry -Dexec.args="config/schema-registry.properties"Build Schema Registry from source
masterTo build the project using Maven, ensure you have the necessary dependencies (like
commonandrest-utils) installed. Use the following commands:- Compile:
mvn compile - Test:
mvn test - Package:
mvn package [-DskipTests] - Standalone Fat JAR:
mvn package -P standalone [-DskipTests](generates a single JAR with all dependencies).
- Compile:
Run Schema Registry JMH Microbenchmarks
masterThe Schema Registry JMH microbenchmarks can be executed directly from the
SerdeBenchmark.javafile using an IDE like IntelliJ, or via the command line after building the module to producetarget/benchmarks.jar.java -jar ./target/benchmarks.jarRun a subset of Schema Registry benchmarks
masterYou can filter the benchmarks by specifying parameters. For example, to run only the AVRO serialization benchmarks, use the
-pflag with theserializationFormatparameter set toAVRO.java -jar ./target/benchmarks.jar -p serializationFormat=AVROFetch schemas by ID or version
masterSchemas can be retrieved in several ways:
- By Global ID: Use
GET /schemas/ids/{id}to fetch a schema by its unique identifier. - By Version: Use
GET /subjects/{subject}/versions/{version}to fetch a specific version of a subject's schema. - By Latest: Use
GET /subjects/{subject}/versions/latestto fetch the most recently registered version for a subject.
# Fetch a schema by globally unique id 1 $ curl -X GET http://localhost:8081/schemas/ids/1 # Fetch version 1 of the schema registered under subject "Kafka-value" $ curl -X GET http://localhost:8081/subjects/Kafka-value/versions/1 # Fetch the most recently registered schema under subject "Kafka-value" $ curl -X GET http://localhost:8081/subjects/Kafka-value/versions/latest- By Global ID: Use
Test schema compatibility
masterTo check if a new schema is compatible with the current latest schema of a subject, send a
POSTrequest to/compatibility/subjects/{subject}/versions/latestwith the new schema in the body. The response will indicate if it is compatible.# Test compatibility of a schema with the latest schema under subject "Kafka-value" $ curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \ --data '{"schema": "{\"type\": \"string\"}"}' \ http://localhost:8081/compatibility/subjects/Kafka-value/versions/latestRegister a new schema version
masterTo register a new version of a schema under a specific subject (e.g.,
Kafka-keyorKafka-value), send aPOSTrequest to the/subjects/{subject}/versionsendpoint. The request must include theContent-Type: application/vnd.schemaregistry.v1+jsonheader and a JSON body containing the schema string.# Register a new version of a schema under the subject "Kafka-key" $ curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \ --data '{"schema": "{\"type\": \"string\"}"}' \ http://localhost:8081/subjects/Kafka-key/versionsList all subjects and schema versions
masterYou can retrieve a list of all registered subjects using a
GETrequest to/subjects. To see all versions registered under a specific subject, useGET /subjects/{subject}/versions.# List all subjects $ curl -X GET http://localhost:8081/subjects # List all schema versions registered under the subject "Kafka-value" $ curl -X GET http://localhost:8081/subjects/Kafka-value/versionsDelete schemas and versions
masterYou can remove specific versions or entire subjects:
- Delete a specific version: Use
DELETE /subjects/{subject}/versions/{version}. - Delete all versions of a subject: Use
DELETE /subjects/{subject}.
# Delete version 3 of the schema registered under subject "Kafka-value" $ curl -X DELETE http://localhost:8081/subjects/Kafka-value/versions/3 # Delete all versions of the schema registered under subject "Kafka-value" $ curl -X DELETE http://localhost:8081/subjects/Kafka-value- Delete a specific version: Use
Configure compatibility settings
masterCompatibility settings can be managed at the global level or per subject:
- Global Config: Use
GET /configto view andPUT /configto update global compatibility requirements. - Subject-specific Config: Use
PUT /config/{subject}to update compatibility requirements for a specific subject.
# Get top level config $ curl -X GET http://localhost:8081/config # Update compatibility requirements globally $ curl -X PUT -H "Content-Type: application/vnd.schemaregistry.v1+json" \ --data '{"compatibility": "NONE"}' \ http://localhost:8081/config # Update compatibility requirements under the subject "Kafka-value" $ curl -X PUT -H "Content-Type: application/vnd.schemaregistry.v1+json" \ --data '{"compatibility": "BACKWARD"}' \ http://localhost:8081/config/Kafka-value- Global Config: Use
Configure Kafka-based leader election client
masterThe
ClientConfigclass is used to parse configuration properties required by Kafka clients used in the leader election process. It extends Kafka'sAbstractConfigand supports standard Kafka client configurations, including SSL and SASL support.When initializing the configuration, you can provide a map of properties. The class includes several default values for network and retry behaviors.