A schema registry is a repository for managing schemas used by your Kafka producers and consumers.
This document shows you how to create a schema registry resource within Managed Service for Apache Kafka using the Google Cloud console, the Google Cloud CLI, or the Managed Kafka API.
Before you begin
Before you create a schema registry, complete the following:
- Create a Managed Service for Apache Kafka cluster in the same region where you are planning to create a schema registry.
Required roles and permissions
To get the permissions that
you need to create a schema registry,
ask your administrator to grant you the
Managed Kafka Schema Registry Editor (roles/managedkafka.schemaRegistryEditor
)
IAM role on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the permissions required to create a schema registry. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to create a schema registry:
-
Grant this permission on the parent location:
managedkafka.schemaRegistries.create
You might also be able to get these permissions with custom roles or other predefined roles.
Higher-level roles like Managed Kafka Schema Registry Admin also lets you create and manage schema registries.
For more information about the predefined roles available for Managed Service for Apache Kafka, see the Access control documentation.
Create a schema registry
Console
- In the Google Cloud console, go to the Schema registries page.
The Schema registries page opens.
- On the Schema registries page, click Create.
The Create Schema registry page opens.
- For Schema registry name, enter a unique identifier for your registry.
The name must start with a letter, contain only letters (a-z, A-Z), numbers (0-9), and underscores (_), and be 63 characters or less.
- Select or enter a Region from the menu.
You must already have a single or multiple active Managed Service for Apache Kafka clusters in the region specified. To check the regions of your clusters, see the documentation about listing your clusters.
For a list of supported locations, see Managed Service for Apache Kafka locations.
- Click Create.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Use the
gcloud beta managed-kafka schema-registries create
command to create a schema registry:gcloud beta managed-kafka schema-registries create SCHEMA_REGISTRY_ID \ --location=LOCATION \
Replace the following:
- SCHEMA_REGISTRY_ID (required): a unique identifier for your new schema registry. This forms part of the registry's resource name. The name must start with a letter, contain only letters (a-z, A-Z), numbers (0-9), and underscores (_), and be 63 characters or less.
- LOCATION (required): the Google Cloud region where the schema registry is going to be created. This location must match the region of the Managed Service for Apache Kafka cluster or clusters using this registry. For supported locations, see Managed Service for Apache Kafka locations.
To create a schema registry named
test_schema_registry
in theus-central1
region, run the following command:gcloud beta managed-kafka schema-registries create test_schema_registry \ --location=us-central1
After the command completes successfully, the schema registry is created. You can then configure Kafka clients to use its URL. To view the schema registry URL, see Schema registry page details.
REST
To create a schema registry instance using the REST API, perform the following steps.
- Send a
POST
request similar to the following: - Create a JSON file
request-body.json
with the following structure:
POST https://managedkafka.googleapis.com/v1main/projects/PROJECT_ID/locations/LOCATION/schemaRegistries Authorization: Bearer $(gcloud auth application-default print-access-token) Content-Type: application/json --data @response-body.json
{ "schemaRegistryId": "SCHEMA_REGISTRY_ID" }
Replace the following:
- SCHEMA_REGISTRY_ID (required): a unique identifier for your new schema registry. This forms part of the registry's resource name. The name must start with a letter, contain only letters (a-z, A-Z), numbers (0-9), and underscores (_), and be 63 characters or less.
Run the POST
request with the constructed URI, headers,
and body. If successful, the API returns a 200 OK
status
code and a response body containing the JSON representation of the newly
created SchemaRegistry resource.
The following is a sample successful response.
{ "name": "projects/testing-311516/locations/us-central1/schemaRegistries/test", "contexts": [ "projects/testing-311516/locations/us-central1/schemaRegistries/test/contexts/." ] }
The
projects/testing-311516/locations/us-central1/schemaRegistries/test/contexts/.
represents the default context. Resources in the default context don't
require any context to be specified.
For more information, see the REST API documentation.