Schema Registry Replication

Configure schema replication to target cluster.

K2K supports migrating schemas from a source cluster to a destination cluster. This page covers the configuration steps required to enable this feature. For now K2K supports Schema Registries compatible with Confluent Schema Registry API.

Requirements

This tutorial assumes the following files exist (See Setting up for more details):

name: "my-first-replication"
features:
  autoCreateControlTopics: enabled
  autoCreateTopics: enabled
source:
  kafka:
    connection:
      servers: "kafka-source:9092"
    consumer:
      "group.id": "k2k.my-first-k2k"
target:
  kafka:
    connection:
      servers: "kafka-target:9092"
coordination:
  kafka:
    commit:
      group: "k2k.my-first-k2k"
replication:
  - source:
      topic: ".*"
  - sink:
      topic: source
      partition: source

To ensure a clean start, execute this command to reset any prior configurations from earlier tutorials.

docker compose down
1

Start the Kafka clusters

docker compose up -d registry-target kafka-target registry-source kafka-source
2

Creating the source cluster topic

Execute these commands to create the "user-topic" topic and add data:

#create a topic
docker compose exec kafka-source \
      ./opt/kafka/bin/kafka-topics.sh \
      --create \
      --topic user-topic \
      --partitions 5 \
      --bootstrap-server 127.0.0.1:9092    

#add some data and register the schema
docker compose exec -it registry-source \
  kafka-avro-console-producer \
      --bootstrap-server kafka-source:9092 \
      --topic user-topic \
      --property schema.registry.url="http://registry-source:8085" \
      --property key.schema='{"type":"record","name":"userKey","fields":[{"name":"id","type":"int"}]}' \
      --property value.schema='{"type":"record","name":"userRecord","fields":[{"name":"user_name","type":"string"}]}'
#paste this message
{"user_name": "my-name"}
3

Run it

Use the following command to run the K2K replicator app:

#start k2k
docker compose up k2k
4

Validating results

K2K now replicates both data and schemas. Querying the subjects endpoint on the target schema registry will display identical schemas as those on the source.

#source
curl localhost:8085/subjects 
#target
curl localhost:8086/subjects 
5

Repeat with different routing strategies

When replicating schemas, K2K considers the record routing strategy. Thus, if you repeat the steps with different routing strategies, such as appending a suffix to the topic name, the replicated subjects will be named according to the routing rule.

For more information about record routing refer to: (Routing Records)

Last updated

Was this helpful?