Important

You are viewing documentation for an older version of Confluent Platform. For the latest, click here.

Using Schema Registry

Starting Schema Registry

Start Schema Registry and its dependent services ZooKeeper and Kafka. Each service reads its configuration from its property files under etc.

Development or Test Environment

You can use the Confluent CLI to start Schema Registry and its dependent services with this command:

confluent start schema-registry

Important

The Confluent CLI is meant for development purposes only and is not suitable for a production environment. The data that are produced are transient and are intended to be temporary.

Production Environment

Start each Confluent Platform service in its own terminal using this order of operations:

  1. Start ZooKeeper. Run this command in its own terminal.

    bin/zookeeper-server-start ./etc/kafka/zookeeper.properties
    
  2. Start Kafka. Run this command in its own terminal.

    bin/kafka-server-start ./etc/kafka/server.properties
    
  3. Start Schema Registry. Run this command in its own terminal.

    bin/schema-registry-start ./etc/schema-registry/schema-registry.properties
    

See the Installing and Upgrading for a more detailed explanation of how to get these services up and running.

Common Schema Registry Usage Examples

These examples use curl commands to interact with the Schema Registry API.

Registering 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
{"id":1}

Registering a New Version of a Schema Under the Subject “Kafka-value”

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
  --data '{"schema": "{\"type\": \"string\"}"}' \
   http://localhost:8081/subjects/Kafka-value/versions
{"id":1}

Listing All Subjects

curl -X GET http://localhost:8081/subjects
["Kafka-value","Kafka-key"]

Fetching a Schema by Globally Unique ID 1

curl -X GET http://localhost:8081/schemas/ids/1
{"schema":"\"string\""}

Listing All Schema Versions Registered Under the Subject “Kafka-value”

curl -X GET http://localhost:8081/subjects/Kafka-value/versions
[1]

Fetch Version 1 of the Schema Registered Under Subject “Kafka-value”

curl -X GET http://localhost:8081/subjects/Kafka-value/versions/1
{"subject":"Kafka-value","version":1,"id":1,"schema":"\"string\""}

Deleting Version 1 of the Schema Registered Under Subject “Kafka-value”

curl -X DELETE http://localhost:8081/subjects/Kafka-value/versions/1
1

Deleting the Most Recently Registered Schema Under Subject “Kafka-value”

curl -X DELETE http://localhost:8081/subjects/Kafka-value/versions/latest
2

Registering the Same Schema Under the Subject “Kafka-value”

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
  --data '{"schema": "{\"type\": \"string\"}"}' \
   http://localhost:8081/subjects/Kafka-value/versions
{"id":1}

Fetching the Schema Again by Globally Unique ID 1

curl -X GET http://localhost:8081/schemas/ids/1
{"schema":"\"string\""}

Checking if a Schema Is Registered Under Subject “Kafka-key”

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
  --data '{"schema": "{\"type\": \"string\"}"}' \
  http://localhost:8081/subjects/Kafka-key
{"subject":"Kafka-key","version":3,"id":1,"schema":"\"string\""}

Testing 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
{"is_compatible":true}

Getting the Top Level Config

curl -X GET http://localhost:8081/config
{"compatibilityLevel":"BACKWARD"}

Updating Compatibility Requirements Globally

curl -X PUT -H "Content-Type: application/vnd.schemaregistry.v1+json" \
  --data '{"compatibility": "NONE"}' \
  http://localhost:8081/config
{"compatibility":"NONE"}

Deleting All Schema Versions Registered Under the Subject “Kafka-value”

curl -X DELETE http://localhost:8081/subjects/Kafka-value
[3]

Listing All Subjects

curl -X GET http://localhost:8081/subjects
["Kafka-key"]