Confluent Schema Registry

repository·master·Indexed 25 days ago

https://github.com/confluentinc/schema-registry

A 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.

Tokens
5K
Snippets
9
Records
36
Agent score
76%

What's inside Confluent Schema Registry

  1. Overview of Confluent Schema Registry

    master
    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.
  2. Build Schema Registry from source

    master

    To build the project using Maven, ensure you have the necessary dependencies (like common and rest-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).
  3. Fetch schemas by ID or version

    master

    Schemas 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/latest to 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
  4. Test schema compatibility

    master

    To check if a new schema is compatible with the current latest schema of a subject, send a POST request to /compatibility/subjects/{subject}/versions/latest with 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/latest
  5. Register a new schema version

    master

    To register a new version of a schema under a specific subject (e.g., Kafka-key or Kafka-value), send a POST request to the /subjects/{subject}/versions endpoint. The request must include the Content-Type: application/vnd.schemaregistry.v1+json header 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/versions
  6. List all subjects and schema versions

    master

    You can retrieve a list of all registered subjects using a GET request to /subjects. To see all versions registered under a specific subject, use GET /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/versions
  7. Delete schemas and versions

    master

    You 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
  8. Configure compatibility settings

    master

    Compatibility settings can be managed at the global level or per subject:

    • Global Config: Use GET /config to view and PUT /config to 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
  9. Configure Kafka-based leader election client

    master

    The ClientConfig class is used to parse configuration properties required by Kafka clients used in the leader election process. It extends Kafka's AbstractConfig and 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.