Manage Schemas for Topics¶
Use the Schema Registry feature in Control Center to manage Confluent Platform topic schemas.
You can:
- create, edit, and view schemas
- compare schema versions
- download schemas
The Schema Registry performs validations and compatibility checks on schemas.
Tip
- Review the step-by-step tutorial for using Schema Registry.
- For comprehensive information on Schema Registry, refer to the Schema Registry documentation.
The Schema Registry feature in Control Center is enabled by default. Disabling the feature disables both viewing and editing of schemas.
Note
As of Confluent Platform version 5.2, schemas can be created and edited. Versions prior to 5.2 only have view access to schema information in Control Center, including comparing version history and downloading schemas.
Creating a topic schema in Control Center¶
Create key and value schemas. Value schemas are typically created more frequently than a key schema.
Best practices:
- Provide default values for fields to facilitate backward-compatibility if pertinent to your schema.
- Document at least the more obscure fields for human-readability of a schema.
To create a topic value schema:
Select a cluster from the navigation bar.
Click the Topics menu. The All Topics page appears.
Click the ellipsis (
...
) by the topic name and click Schema.You are prompted to set a message value schema.
Click Set a schema. The Schema editor appears.
The basic structure of a schema appears prepopulated in the editor as a starting point. Enter the schema in the editor:
name
: Enter a name for the schema if you do not want to accept the default, which is determined by the subject name strategy. The default is schema_type_topic_name. Required.type
: Eitherrecord
,enum
,union
,array
,map
, orfixed
. Required.namespace
: Fully-qualified name to prevent schema naming conflicts. String that qualifies the schemaname
. Optional but recommended.fields
: JSON array listing one or more fields for a record. Required.Each field can have the following attributes:
name
: Name of the field. Required.doc
: Field metadata. Optional but recommended.default
: Default value for a field. Optional but recommended.order
: Sorting order for a field. Valid values are ascending, descending, or ignore. Default: Ascending. Optional.aliases
: Alternative names for a field. Optional.
Copy and paste the following example schema:
{ "namespace": "io.confluent.examples.clients.basicavro", "type": "record", "name": "Payment", "fields": [ { "name": "id", "type": "string" }, { "name": "amount", "type": "double" } ] }
Click Save.
- If the entered schema is valid, the Schema updated message is briefly displayed in the banner area.
- If the entered schema is not valid, an Input schema is an invalid Avro schema error is displayed in the banner area.
If applicable, repeat the procedure as appropriate for the topic key schema.
To create a topic key schema:
Click the Key option. You are prompted to set a message key schema.
Click Set a schema.
Enter the schema into the editor and click Save.
Tip
Kafka messages are key/value pairs. Message keys and message values can be
serialized independently. For example, the value may be using an
Avro record
,
while the key may be a primitive (string
, integer
, and so forth).
Typically message keys, if used, are primitives, but they can be complex data types
as well (for example, record
or array
). How you set the key is up to you
and the requirements of your implementation. For detailed examples of key and value schemas,
see the discussion under Serializer in the Schema Registry documentation.
Viewing a schema in Control Center¶
View the schema details for a specific topic.
Select a cluster from the navigation bar.
Click the Topics menu. The All Topics page appears.
Click the ellipsis (
...
) by the topic name and click Schema.The Value schema is displayed by default.
Click Key to view the key schema if present.
Editing a schema in Control Center¶
Edit an existing schema for a topic.
Select a cluster from the navigation bar.
Click the Topics menu. The All Topics page appears.
Click the ellipsis (
...
) by the topic name and click Schema.Select the Key or Value option for the schema.
Make the changes in the schema editor.
Click Save.
If the schema update is valid and compatible with its prior versions (assuming a backward-compatible mode), the schema is updated and the version count is incremented. You can compare the different versions of a schema.
If the schema update is invalid or incompatible with an earlier schema version, an error is displayed.
Comparing schema versions in Control Center¶
Compare versions of a schema to view its evolutionary differences.
Select a cluster from the navigation bar.
Click the Topics menu. The All Topics page appears.
Click the ellipsis (
...
) by the topic name and click Schema.Select the Key or Value option for the schema.
Click Version history.
The current version number of a schema displays in the upper-right corner of the Schema pane, and is also indicated in the version menus.
Select the Turn on version diff check box.
Select the versions to compare from each version menu. The differences are highlighted for comparison.
Changing the compatibility mode of a schema in Control Center¶
The default compatibility mode is Backward. The mode can be changed for the schema of any topic if necessary.
Caution
If you change the compatibility mode of an existing schema already in production use, be aware of any possible breaking changes to your applications.
Select a cluster from the navigation bar.
Click the Topics menu. The All Topics page appears.
Click the ellipsis (
...
) by the topic name and click Schema.Select the Key or Value option for the schema.
Click Edit Schema -> Compatibility Mode tab.
Select a mode option:
- Backward (Confluent Schema Registry default)
- Transitive backward
- Forward
- Transitive forward
- Full
- Transitive full
- None (not recommended)
Descriptions indicate the compatibility behavior for each option. For more information, including the changes allowed for each option, see Schema Evolution and Compatibility.
Click Save.
Downloading a schema from Control Center¶
Select a cluster from the navigation bar.
Click the Topics menu. The All Topics page appears.
Click the ellipsis (
...
) by the topic name and click Schema.Select the Key or Value option for the schema.
Click Download. A schema JSON file for the topic is downloaded into your Downloads directory.
Example filename:
schema-transactions-v1-Ry_XaOGvTxiZVZ5hbBhWRA.json
Example contents:
{"subject":"transactions-value","version":1,"id":2,"schema":"{\"type\":\"record\",\"name\":\"Payment\", \"namespace\":\"io.confluent.examples.clients.basicavro\", \"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"amount\",\"type\":\"double\"}, {\"name\":\"region\",\"type\":\"string\"}]}"}
This is the first version of the schema, and it has an
id
of 2. The schema is escaped JSON. A backslash precedes double-quotes.
Troubleshoot Schema Registry is not set up message¶
If the Schema Registry is not set up page appears when you try to access the Topic Schema feature in Control Center, verify
that the Schema Registry listeners
configuration matches the
Control Center confluent.controlcenter.schema.registry.url
configuration. Also check the
HTTPS configuration parameters.
For more information, see A schema for message values has not been set for this topic.
Enabling and disabling Schema Registry in Control Center¶
The feature that allows working with schemas in Control Center is enabled by default. The feature can be disabled if an organization does not want any users to access the feature. After disabling the feature, the Topics Schema menu and the Schema tab are no longer visible in the Control Center UI. The ability to view and edit schemas is disabled.
To disable the edit schema feature in Control Center:
Set the
confluent.controlcenter.schema.registry.enable
option in yourcontrol-center.properties
file tofalse
.... confluent.controlcenter.schema.registry.enable=false ...
Note
Make the change in the appropriate Control Center properties file or files configured for your environments, including
control-center-dev.properties
orcontrol-center-production.properties
. The properties files are located in/path-to-confluent/etc/confluent-control-center/
.Restart Control Center and pass in the properties file for the configuration to take effect:
./bin/control-center-stop ./bin/control-center-start ../etc/confluent-control-center/control-center.properties
Tip
If you are using a Confluent Platform development environment with a confluent local, stop and start as follows:
./confluent local stop control-center ./confluent local start control-center ../etc/confluent-control-center/control-center-dev.properties
To enable the feature again, set the option back to true
and restart Control Center with the updated properties file.