<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Steven van Rossum on Medium]]></title>
        <description><![CDATA[Stories by Steven van Rossum on Medium]]></description>
        <link>https://medium.com/@sjvanrossum?source=rss-30b5bd3b6d4c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YSYXoo3dIU5-TgcJdiYQjg.png</url>
            <title>Stories by Steven van Rossum on Medium</title>
            <link>https://medium.com/@sjvanrossum?source=rss-30b5bd3b6d4c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 20:18:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sjvanrossum/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Running Schema Registry with Google Cloud Managed Service for Apache Kafka]]></title>
            <link>https://medium.com/google-cloud/running-schema-registry-with-google-cloud-managed-service-for-apache-kafka-5de1c5aada3f?source=rss-30b5bd3b6d4c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5de1c5aada3f</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[kafka-schema-registry]]></category>
            <dc:creator><![CDATA[Steven van Rossum]]></dc:creator>
            <pubDate>Fri, 01 Nov 2024 14:24:40 GMT</pubDate>
            <atom:updated>2024-11-10T10:01:10.664Z</atom:updated>
            <content:encoded><![CDATA[<p>My earliest memory of portable data models — or schemas — would probably be from a book I read about XML schemas circa 2004. The data workloads that you and I develop today most likely handle very different formats compared to then, but schemas and their evolution have mostly remained the same except they’re everywhere nowadays and rightfully so. Evolving schemas and adopting new data and schema formats used to be comparatively simple in batch processing systems, but it’s a lot more challenging in stream processing systems which need to be continuously operational and handle the gradual evolution of schemas on the fly. Effective communication of the schema is key if you want to simplify that process as a data producer or consumer. Providing the schema or its ID as a custom preamble to a message, on a message envelope or as stream metadata might be your only resort and the apparent lack of standardized and interoperable methods to describe the format and schema of messages, like a Content-Type header, leaves some things to be desired of some streaming platforms, but that’s not unique to streaming platforms.</p><p>De facto standards bridge the gap, but you might almost forget that they’re not a core component of your streaming platform. I certainly did when I recently spun up a fresh Kafka cluster using <a href="https://cloud.google.com/products/managed-service-for-apache-kafka">Google Cloud Managed Service for Apache Kafka</a> and realized that <a href="https://kafka.apache.org/">Apache Kafka</a> is among the unfortunate souls to lack a built-in schema registry. I was in the midst of rewiring the deployment configuration for a workload and paused when I came across the configuration key schema.registry.url. While the Apache Kafka project doesn’t ship with a built-in schema registry, your workload may depend on Confluent Schema Registry (or an API-compatible alternative) and understandably so given that its API is considered a de facto standard when it comes to schema registries for Apache Kafka.</p><p>Setting up a schema registry is a minor nuisance, but I’d rather not provision virtual machines or a whole Kubernetes cluster just to run a single service alongside the fully managed Apache Kafka cluster I just created. There are plenty of Confluent Schema Registry-compatible services to pick from, but to interact with my new cluster I’ll need to provide sasl.mechanism=OAUTHBEARER and add a custom callback handler. An implementation of the callback handler is provided by Google on GitHub at <a href="https://github.com/googleapis/managedkafka">googleapis/managedkafka</a>, but do note that it restricts my schema registry options to those that are compatible with the Apache Kafka client library for Java.</p><h3>Creating a Schema Registry</h3><p>Confluent Schema Registry works just fine with the requirements above, so to test this out I went ahead and spun up the <a href="https://hub.docker.com/r/confluentinc/cp-schema-registry">confluentinc/cp-schema-registry</a> container image on a Cloud Workstations instance connected to my project’s network. The callback handler jar and its dependencies (note: replace guava-X.Y.Z-android.jar with guava-X.Y.Z-jre.jar) need to be present on the classpath used by the container image’s entrypoint and Schema Registry server. The callback handler requires GCP credentials to be provided through any means compatible with Application Default Credentials such as those stored by the Google Cloud SDK in ~/.config/gcloud. I used the script below to create a local Schema Registry instance and run a quick test:</p><pre>JARS_DIRECTORY=/path/to/jars<br>REGION_NAME=us-central1<br>PROJECT_NAME=my-project<br>VERSION_TAG=1.2.3<br>CLUSTER_NAME=my-cluster<br>CLUSTER_BOOTSTRAP_HOSTNAME=&quot;bootstrap.${CLUSTER_NAME}.${REGION_NAME}.managedkafka.${PROJECT_NAME}.cloud.goog&quot;<br><br># Create the container<br>CONTAINER_ID=$(docker run --rm -d \<br>  -v ~/.config/gcloud:/home/appuser/.config/gcloud \<br>  -v &quot;${JARS_DIRECTORY}:/usr/share/java/google-managed-kafka&quot; \<br>  -p 8081:8081 \<br>  -e &#39;CUB_CLASSPATH=/usr/share/java/google-managed-kafka/*:/usr/share/java/cp-base-new/*&#39; \<br>  -e &#39;CLASSPATH=/usr/share/java/google-managed-kafka/*&#39; \<br>  -e &quot;SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS=${CLUSTER_BOOTSTRAP_HOSTNAME}:9092&quot; \<br>  -e SCHEMA_REGISTRY_KAFKASTORE_SECURITY_PROTOCOL=SASL_SSL \<br>  -e SCHEMA_REGISTRY_KAFKASTORE_SASL_MECHANISM=OAUTHBEARER \<br>  -e SCHEMA_REGISTRY_KAFKASTORE_SASL_LOGIN_CALLBACK_HANDLER_CLASS=com.google.cloud.hosted.kafka.auth.GcpLoginCallbackHandler \<br>  -e &#39;SCHEMA_REGISTRY_KAFKASTORE_SASL_JAAS_CONFIG=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;&#39; \<br>  -e SCHEMA_REGISTRY_HOST_NAME=localhost \<br>  &quot;confluentinc/cp-schema-registry:${VERSION_TAG}&quot;)<br><br># Create a schema version, retry while the container is starting up<br>curl -X POST \<br>  --data &#39;{&quot;schema&quot;: &quot;{\&quot;type\&quot;: \&quot;string\&quot;}&quot;}&#39; \<br>  -H &#39;Content-Type: application/vnd.schemaregistry.v1+json&#39; \<br>  http://localhost:8081/subjects/my-schema/versions \<br>  --retry 3 \<br>  --retry-all-errors \<br>  --retry-delay 30<br><br># List all schemas<br>curl -X GET \<br>  http://localhost:8081/subjects<br><br># Clean up the container<br>docker kill &quot;${CONTAINER_ID}&quot;</pre><h3>To the Cloud!</h3><p>At this point I could continue developing a data processing pipeline and test it locally, but it would be useful if I could run this somewhere in my Google Cloud project. Using the container image to start a Cloud Run Service is almost as easy as running the container image locally. A Cloud Storage bucket with the callback handler jar and its dependencies can be used to attach a volume to the Cloud Run Service. One thing to note is that Schema Registry uses a single instance to coordinate writes to the Kafka topic. Normally multiple instances would coordinate among themselves which instance will fulfill that role, but Cloud Run does not support direct communication between instances of the same service. The Cloud Run Service should thus be limited to a single instance and ideally keep that instance up and running since the Schema Registry server will read the entire Kafka topic and cache its contents locally on startup.</p><pre>JARS_DIRECTORY=/path/to/jars<br>JARS_BUCKET=my-bucket<br>REGION_NAME=us-central1<br>PROJECT_NAME=my-project<br>PROJECT_NUMBER=1234567890<br>NETWORK_NAME=my-network<br>VERSION_TAG=1.2.3<br>CLUSTER_NAME=my-cluster<br>CLUSTER_BOOTSTRAP_HOSTNAME=&quot;bootstrap.${CLUSTER_NAME}.${REGION_NAME}.managedkafka.${PROJECT_NAME}.cloud.goog&quot;<br>CLOUD_RUN_SERVICE_NAME=my-schema-registry<br>CLOUD_RUN_SERVICE_HOSTNAME=&quot;${CLOUD_RUN_SERVICE_NAME}-${PROJECT_NUMBER}.${REGION_NAME}.run.app&quot;<br><br># Create the bucket, if needed<br>gcloud storage buckets create &quot;gs://${JARS_BUCKET}&quot; \<br>  -b \<br>  -l &quot;${REGION_NAME}&quot; \<br>  --project &quot;${PROJECT_NAME}&quot;<br><br># Copy the jars to the bucket<br>gcloud storage cp -R &quot;${JARS_DIRECTORY}&quot; &quot;gs://${JARS_BUCKET}&quot;<br><br># Create the service, alternatively use --allow-unauthenticated<br>gcloud run deploy &quot;${CLOUD_RUN_SERVICE_NAME}&quot; \<br>  --project &quot;${PROJECT_NAME}&quot; \<br>  --region &quot;${REGION_NAME}&quot; \<br>  --image &quot;confluentinc/cp-schema-registry:${VERSION_TAG}&quot; \<br>  --max-instances 1 \<br>  --min-instances 1 \<br>  --port 8081 \<br>  --ingress internal \<br>  --network &quot;${NETWORK_NAME}&quot; \<br>  --add-volume &quot;name=jars,type=cloud-storage,bucket=${JARS_BUCKET}&quot; \<br>  --add-volume-mount volume=jars,mount-path=/usr/share/java/google-managed-kafka \<br>  --update-env-vars &#39;CUB_CLASSPATH=/usr/share/java/google-managed-kafka/*:/usr/share/java/cp-base-new/*&#39; \<br>  --update-env-vars &#39;CLASSPATH=/usr/share/java/google-managed-kafka/*&#39; \<br>  --update-env-vars &quot;SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS=${CLUSTER_BOOTSTRAP_HOSTNAME}:9092&quot; \<br>  --update-env-vars SCHEMA_REGISTRY_KAFKASTORE_SECURITY_PROTOCOL=SASL_SSL \<br>  --update-env-vars SCHEMA_REGISTRY_KAFKASTORE_SASL_MECHANISM=OAUTHBEARER \<br>  --update-env-vars SCHEMA_REGISTRY_KAFKASTORE_SASL_LOGIN_CALLBACK_HANDLER_CLASS=com.google.cloud.hosted.kafka.auth.GcpLoginCallbackHandler \<br>  --update-env-vars &#39;SCHEMA_REGISTRY_KAFKASTORE_SASL_JAAS_CONFIG=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;&#39; \<br>  --update-env-vars &quot;SCHEMA_REGISTRY_HOST_NAME=${CLOUD_RUN_SERVICE_HOSTNAME}&quot; \<br>  --no-allow-unauthenticated<br><br># Create a schema version, leave out the Authorization header when using --allow-unauthenticated<br>curl -X POST \<br>  --data &#39;{&quot;schema&quot;: &quot;{\&quot;type\&quot;: \&quot;string\&quot;}&quot;}&#39; \<br>  -H &quot;Authorization: Bearer $(gcloud auth print-identity-token)&quot; \<br>  -H &#39;Content-Type: application/vnd.schemaregistry.v1+json&#39; \<br>  &quot;https://${CLOUD_RUN_SERVICE_HOSTNAME}/subjects/my-schema/versions&quot;<br><br># List all schemas, leave out the Authorization header when using --allow-unauthenticated<br>curl -X GET \<br>  -H &quot;Authorization: Bearer $(gcloud auth print-identity-token)&quot; \<br>  &quot;https://${CLOUD_RUN_SERVICE_HOSTNAME}/subjects&quot;<br><br># Clean up the service<br>gcloud run services delete &quot;${CLOUD_RUN_SERVICE_NAME}&quot; \<br>  --project &quot;${PROJECT_NAME}&quot; \<br>  --region &quot;${REGION_NAME}&quot; \<br>  --quiet</pre><h3>That’s a wrap</h3><p>That should get you on your way to use a schema registry with Google Cloud Managed Service for Apache Kafka. Check out some of the other Apache Kafka stories in the Google Cloud community to learn more about operating and using a cluster with Google Cloud Managed Service for Apache Kafka:</p><ul><li><a href="https://medium.com/google-cloud/local-development-with-google-cloud-managed-service-for-apache-kafka-8a50b2efb5ab">Local Development with Google Cloud Managed Service for Apache Kafka</a></li><li><a href="https://medium.com/google-cloud/using-oauth-to-connect-to-google-managed-service-for-apache-kafka-b0b7bcb86c4b">Using OAuth to connect to Google Managed Service for Apache Kafka</a></li><li><a href="https://medium.com/google-cloud/the-schema-registry-api-is-not-how-you-use-schema-with-kafka-3adb92f09764">The Schema Registry API is not how you use schema with Kafka!</a></li><li><a href="https://medium.com/@kir-gcp/the-fear-of-oauth-with-apache-kafka-schema-registry-and-how-to-conquer-it-64496ce88d2b">A secure Schema Registry with OAuth: tricks &amp; treats.</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5de1c5aada3f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/running-schema-registry-with-google-cloud-managed-service-for-apache-kafka-5de1c5aada3f">Running Schema Registry with Google Cloud Managed Service for Apache Kafka</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>