Skip to content

Instantly share code, notes, and snippets.

@pavelfomin
Last active September 7, 2023 15:10
Show Gist options
  • Save pavelfomin/1b3fd94aae855d081d24abaf5f43e8dd to your computer and use it in GitHub Desktop.
Save pavelfomin/1b3fd94aae855d081d24abaf5f43e8dd to your computer and use it in GitHub Desktop.
Confluent Schema Registry Metadata

Confluent Schema Registry Metadata

Prior to v7.4, schema registry did not support any custom metadata associated with a schema uploaded to the schema registry.

So the following mapping between

  • the version of a jar artifact containing a schema content
  • and the id and version of the schema in the schema registry can only be derived by comparing the content of the schemas in different schema registry environments (using POST /subjects/(string: subject)).

Starting with v7.4, it is possible to add any metadata properties to the schema registration call:

curl -s --show-error --fail --insecure --user : -H 'Content-Type: application/vnd.schemaregistry.v1+json' http://localhost:9080/subjects/test-topic-value/versions --data '{
  "schema": "{\n  \"type\" : \"record\",\n  \"name\" : \"TestSchema\",\n  \"namespace\" : \"com.droidablebee.avro\",\n  \"fields\" : [ {\n    \"name\" : \"id\",\n    \"type\" : \"string\"\n  }, {\n    \"name\" : \"description\",\n    \"type\" : [ \"null\", \"string\" ],\n    \"default\" : null\n  } ]\n}",
  "metadata": {
    "properties": {
      "artifact": "test-schema-0.0.7.1.zip"
    }
  }
}'

And then see the metadata returned by http://localhost:9080/subjects/test-topic-value/versions/1

{
  "subject": "test-topic-value",
  "version": 1,
  "id": 2,
  "metadata": {
    "properties": {
      "artifact": "test-schema-0.0.7.1.zip"
    }
  },
  "schema": "{\"type\":\"record\",\"name\":\"TestSchema\",\"namespace\":\"com.droidablebee.avro\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"description\",\"type\":[\"null\",\"string\"],\"default\":null}]}"
}

Tested using confluentinc/cp-schema-registry:7.4.1 and confluentinc/cp-schema-registry:7.5.0 docker images.

See https://docs.confluent.io/platform/7.4/schema-registry/develop/api.html and https://docs.confluent.io/platform/7.5/schema-registry/fundamentals/data-contracts.html#metadata-properties for more details.

@pavelfomin
Copy link
Author

When using /subjects/$subject API to check whether a schema is already registered or not, the payload must match the schema registration payload, including metadata properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment