Skip to content

Register missing schema versions during a Kafka sync

The target registry is behind. Which versions get appended?

Terminal recording of kurkik kafka sync

The recording shows kurkik kafka sync on the demo sandbox; its data differs from this example.

Nothing changes yet. --dry-run only shows what would happen.

$ kurkik kafka sync a.yaml b --schemas --overwrite --dry-run
Sync a.yaml into b - Apache Kafka, cluster MkU3OEVBNTcwNTJENDM2Qk
owns: the whole cluster - the document names no x-kurkik.kafka.server.topicPrefixes; access, as x-kurkik.kafka.server.acl declares it
plan: <digest>
Run one sync per cluster at a time: two at once each plan against a state the other is changing.
changes (3)
~ set orders.created-value compatibility NONE -> BACKWARD
+ register orders.created-value version 2 (not set) -> v2 Avro
Appended to orders.created-value after the versions it has; the registry checks it against them at the subject's compatibility level.
+ register payments.settled-value version 2 (not set) -> v2 Protobuf
Appended to payments.settled-value after the versions it has; the registry checks it against them at the subject's compatibility level.
left alone (9)
not decided customers.updated groupId
Nothing about this can be checked against the system, so sync cannot bring it into line. Operation 'receive_customers.updated' declares no consumer group, so there is nothing a broker could confirm.
not decided orders.created groupId
Nothing about this can be checked against the system, so sync cannot bring it into line. Operation 'receive_orders.created' declares no consumer group, so there is nothing a broker could confirm.
not decided payments.settled groupId
Nothing about this can be checked against the system, so sync cannot bring it into line. Operation 'receive_payments.settled' declares no consumer group, so there is nothing a broker could confirm.
not decided customers.updated action
Nothing about this can be checked against the system, so sync cannot bring it into line. A broker cannot know who publishes to 'customers.updated', so operation 'send_customers.updated' is not checked.
not decided orders.created action
Nothing about this can be checked against the system, so sync cannot bring it into line. A broker cannot know who publishes to 'orders.created', so operation 'send_orders.created' is not checked.
not decided payments.settled action
Nothing about this can be checked against the system, so sync cannot bring it into line. A broker cannot know who publishes to 'payments.settled', so operation 'send_payments.settled' is not checked.
extra customers.updated version 2
version 2 on customers.updated is on the system and not in the document. sync leaves what it does not describe as it is.
and 2 differences sync does not act on - servers, messages, undeclared settings; kurkik kafka diff shows them
applying needs: DESCRIBE and DESCRIBE_CONFIGS on the topics it reads; write access to the schema registry's subject orders.created-value; write access to the schema registry's subject payments.settled-value
3 changes
rehearsal
[?] not attempted set orders.created-value compatibility NONE -> BACKWARD
not rehearsed: it has no validate-only form
[?] not attempted register orders.created-value version 2 (not set) -> v2 Avro
not rehearsed: it has no validate-only form
[?] not attempted register payments.settled-value version 2 (not set) -> v2 Protobuf
not rehearsed: it has no validate-only form
The cluster would accept every request it was shown. 3 could not be rehearsed - Kafka has no validate-only deletion or ACL change, and a schema registry no validate-only write. Nothing was changed.
exit 2
$ kurkik kafka sync a.yaml b --schemas --overwrite --yes
Sync a.yaml into b - Apache Kafka, cluster MkU3OEVBNTcwNTJENDM2Qk
owns: the whole cluster - the document names no x-kurkik.kafka.server.topicPrefixes; access, as x-kurkik.kafka.server.acl declares it
plan: <digest>
Run one sync per cluster at a time: two at once each plan against a state the other is changing.
changes (3)
~ set orders.created-value compatibility NONE -> BACKWARD
+ register orders.created-value version 2 (not set) -> v2 Avro
Appended to orders.created-value after the versions it has; the registry checks it against them at the subject's compatibility level.
+ register payments.settled-value version 2 (not set) -> v2 Protobuf
Appended to payments.settled-value after the versions it has; the registry checks it against them at the subject's compatibility level.
left alone (9)
not decided customers.updated groupId
Nothing about this can be checked against the system, so sync cannot bring it into line. Operation 'receive_customers.updated' declares no consumer group, so there is nothing a broker could confirm.
not decided orders.created groupId
Nothing about this can be checked against the system, so sync cannot bring it into line. Operation 'receive_orders.created' declares no consumer group, so there is nothing a broker could confirm.
not decided payments.settled groupId
Nothing about this can be checked against the system, so sync cannot bring it into line. Operation 'receive_payments.settled' declares no consumer group, so there is nothing a broker could confirm.
not decided customers.updated action
Nothing about this can be checked against the system, so sync cannot bring it into line. A broker cannot know who publishes to 'customers.updated', so operation 'send_customers.updated' is not checked.
not decided orders.created action
Nothing about this can be checked against the system, so sync cannot bring it into line. A broker cannot know who publishes to 'orders.created', so operation 'send_orders.created' is not checked.
not decided payments.settled action
Nothing about this can be checked against the system, so sync cannot bring it into line. A broker cannot know who publishes to 'payments.settled', so operation 'send_payments.settled' is not checked.
extra customers.updated version 2
version 2 on customers.updated is on the system and not in the document. sync leaves what it does not describe as it is.
and 2 differences sync does not act on - servers, messages, undeclared settings; kurkik kafka diff shows them
applying needs: DESCRIBE and DESCRIBE_CONFIGS on the topics it reads; write access to the schema registry's subject orders.created-value; write access to the schema registry's subject payments.settled-value
3 changes
applied
[+] done set orders.created-value compatibility NONE -> BACKWARD
[+] done register orders.created-value version 2 (not set) -> v2 Avro
[+] done register payments.settled-value version 2 (not set) -> v2 Protobuf
Applied 3 of 3 changes - 9 left alone
snapshot: ~/.local/state/kurkik/sync/b/b-<time>.snapshot.yaml
rollback: ~/.local/state/kurkik/sync/b/b-<time>.rollback.yaml
undo: kurkik kafka sync revert ~/.local/state/kurkik/sync/b/b-<time>.snapshot.yaml
exit 0

Written before the first change.

rollback.yaml
system: "Apache Kafka"
target: "MkU3OEVBNTcwNTJENDM2Qk"
createdAt: "<time>"
document: "~/.local/state/kurkik/sync/b/b-<time>.snapshot.yaml"
entries:
- forAction: "set-setting:orders.created:compatibility"
undo: "SET_SETTING"
target: "orders.created"
field: "compatibility"
preState:
value: "NONE"
override: true
definition:
scope: "MESSAGE"
subject: "orders.created-value"
- forAction: "register-schema:orders.created:version 2"
undo: "DELETE_REGISTERED_SCHEMA"
target: "orders.created"
field: "version 2"
note: "sync registered this. Undoing it soft-deletes the version again."
definition:
"1.format": "AVRO"
"1.schema": "{\"type\":\"record\",\"name\":\"OrderCreated\",\"namespace\":\"com.shop.orders\"\
,\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"total\",\"type\"\
:\"long\"},{\"name\":\"note\",\"type\":[\"null\",\"string\"],\"default\":null}]}"
"1.version": "2"
count: "1"
part: "VALUE"
position: "2"
registered: "2"
subject: "orders.created-value"
- forAction: "register-schema:payments.settled:version 2"
undo: "DELETE_REGISTERED_SCHEMA"
target: "payments.settled"
field: "version 2"
note: "sync registered this. Undoing it soft-deletes the version again."
definition:
"1.format": "PROTOBUF"
"1.schema": "syntax = \"proto3\";\npackage com.shop.payments;\n\nmessage PaymentSettled\
\ {\n string id = 1;\n int64 cents = 2;\n optional string currency = 3;\n\
}\n"
"1.version": "2"
count: "1"
part: "VALUE"
position: "2"
registered: "2"
subject: "payments.settled-value"

Download rollback.yaml

$ kurkik kafka sync revert ~/.local/state/kurkik/sync/b/b-<time>.snapshot.yaml b --force --yes
Revert b to b-<time>.snapshot.yaml - Apache Kafka, cluster MkU3OEVBNTcwNTJENDM2Qk
owns: what the run being undone changed, as its rollback records it
plan: <digest>
Run one sync per cluster at a time: two at once each plan against a state the other is changing.
changes (3)
- soft-del payments.settled-value version 2 v2 -> (not set) [soft-deletes schema versions]
Soft-deletes what sync registered in payments.settled-value; a client that resolved one of them by id still can, by version it cannot.
- soft-del orders.created-value version 2 v2 -> (not set) [soft-deletes schema versions]
Soft-deletes what sync registered in orders.created-value; a client that resolved one of them by id still can, by version it cannot.
~ set orders.created-value compatibility BACKWARD -> NONE
applying needs: DESCRIBE and DESCRIBE_CONFIGS on the topics it reads; write access to the schema registry's subject payments.settled-value; write access to the schema registry's subject orders.created-value
3 changes, 2 destroy
applied
[+] done soft-del payments.settled-value version 2 v2 -> (not set)
[+] done soft-del orders.created-value version 2 v2 -> (not set)
[+] done set orders.created-value compatibility BACKWARD -> NONE
Applied 3 of 3 changes
snapshot: ~/.local/state/kurkik/sync/b/b-<time>.snapshot.yaml
rollback: ~/.local/state/kurkik/sync/b/b-<time>.rollback.yaml
undo: kurkik kafka sync revert ~/.local/state/kurkik/sync/b/b-<time>.snapshot.yaml
exit 0

After the revert, compared with how it was before: Drift: 0 changed · 0 unmanaged · 0 missing (no drift) - 39 matched

source.yaml, 296 lines
asyncapi: 3.0.0
info:
title: a Apache Kafka API
version: 1.0.0-SNAPSHOT
description: "Generated by reading the a cluster. Cluster id: MkU3OEVBNTcwNTJENDM2Qk."
servers:
broker-1:
host: a-kafka-1:9092
protocol: kafka
protocolVersion: "4.4"
bindings:
kafka:
bindingVersion: 0.5.0
schemaRegistryUrl: http://registry-a:8080
schemaRegistryVendor: apicurio
x-kurkik:
kafka:
server:
schemaRegistryUrl: http://registry-a:8080
schemaRegistryVendor: apicurio
security:
- security: PLAINTEXT
securityProtocol: PLAINTEXT
acl: []
groups: []
brokerConfiguration:
advertised.listeners: "INTERNAL://kafka-1:19092,EXTERNAL://a-kafka-1:9092"
authorizer.class.name: org.apache.kafka.metadata.authorizer.StandardAuthorizer
broker.id: "1"
controller.listener.names: CONTROLLER
controller.quorum.voters: 1@kafka-1:9093
group.initial.rebalance.delay.ms: "0"
inter.broker.listener.name: INTERNAL
listener.security.protocol.map: "INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,CONTROLLER:PLAINTEXT"
listeners: "INTERNAL://0.0.0.0:19092,EXTERNAL://0.0.0.0:9092,CONTROLLER://0.0.0.0:9093"
min.insync.replicas: "1"
node.id: "1"
offsets.topic.replication.factor: "1"
process.roles: "broker,controller"
transaction.state.log.min.isr: "1"
transaction.state.log.replication.factor: "1"
clientConfiguration:
bootstrap.servers: a-kafka-1:9092
security.protocol: PLAINTEXT
groupConfiguration: {}
producerConfiguration: {}
consumerConfiguration: {}
channels:
customers.updated:
address: customers.updated
messages:
customers.updated-value:
payload:
schemaFormat: application/schema+json;version=draft-07
schema:
$schema: http://json-schema.org/draft-07/schema#
title: Customer
type: object
properties:
id:
type: string
required:
- id
name: customers.updated-value
title: customers.updated
summary: "Schema read from the Apicurio Registry: subject customers.updated-value,\
\ version 1."
bindings:
kafka:
bindingVersion: 0.5.0
schemaIdLocation: header
schemaLookupStrategy: TopicIdStrategy
x-kurkik:
kafka:
message:
schemaIdLocation: header
schemaLookupStrategy: TopicIdStrategy
schemaCompatibility: NONE
bindings:
kafka:
bindingVersion: 0.5.0
partitions: 3
replicas: 1
topicConfiguration:
cleanup.policy:
- compact
x-kurkik:
kafka:
channel:
topic: customers.updated
partitions: 3
replicas: 1
topicConfiguration:
cleanup.policy: compact
orders.created:
address: orders.created
messages:
orders.created-value:
payload:
schemaFormat: application/vnd.apache.avro;version=1.9.0
schema:
type: record
name: OrderCreated
namespace: com.shop.orders
fields:
- name: id
type: string
- name: total
type: long
- name: note
type:
- "null"
- string
default: null
name: orders.created-value
title: orders.created
summary: "Schema read from the Apicurio Registry: subject orders.created-value,\
\ version 2."
bindings:
kafka:
bindingVersion: 0.5.0
schemaIdLocation: header
schemaLookupStrategy: TopicIdStrategy
x-kurkik:
kafka:
message:
schemaIdLocation: header
schemaLookupStrategy: TopicIdStrategy
schemaCompatibility: BACKWARD
schemaVersions:
- version: 1
schemaFormat: application/vnd.apache.avro;version=1.9.0
schema:
type: record
name: OrderCreated
namespace: com.shop.orders
fields:
- name: id
type: string
- name: total
type: long
- version: 2
schemaFormat: application/vnd.apache.avro;version=1.9.0
schema:
type: record
name: OrderCreated
namespace: com.shop.orders
fields:
- name: id
type: string
- name: total
type: long
- name: note
type:
- "null"
- string
default: null
bindings:
kafka:
bindingVersion: 0.5.0
partitions: 3
replicas: 1
topicConfiguration:
retention.ms: 604800000
x-kurkik:
kafka:
channel:
topic: orders.created
partitions: 3
replicas: 1
topicConfiguration:
retention.ms: "604800000"
payments.settled:
address: payments.settled
messages:
payments.settled-value:
payload:
schemaFormat: application/vnd.google.protobuf;version=3
schema: |
syntax = "proto3";
package com.shop.payments;
message PaymentSettled {
string id = 1;
int64 cents = 2;
optional string currency = 3;
}
name: payments.settled-value
title: payments.settled
summary: "Schema read from the Apicurio Registry: subject payments.settled-value,\
\ version 2."
bindings:
kafka:
bindingVersion: 0.5.0
schemaIdLocation: header
schemaLookupStrategy: TopicIdStrategy
x-kurkik:
kafka:
message:
schemaIdLocation: header
schemaLookupStrategy: TopicIdStrategy
schemaCompatibility: NONE
schemaVersions:
- version: 1
schemaFormat: application/vnd.google.protobuf;version=3
schema: |
syntax = "proto3";
package com.shop.payments;
message PaymentSettled {
string id = 1;
int64 cents = 2;
}
- version: 2
schemaFormat: application/vnd.google.protobuf;version=3
schema: |
syntax = "proto3";
package com.shop.payments;
message PaymentSettled {
string id = 1;
int64 cents = 2;
optional string currency = 3;
}
bindings:
kafka:
bindingVersion: 0.5.0
partitions: 3
replicas: 1
x-kurkik:
kafka:
channel:
topic: payments.settled
partitions: 3
replicas: 1
topicConfiguration:
min.insync.replicas: "1"
retention.bytes: "10737418240"
operations:
receive_customers.updated:
action: receive
channel:
$ref: "#/channels/customers.updated"
x-kurkik:
kafka:
operation:
security: []
consumerConfiguration: {}
groupConfiguration: {}
receive_orders.created:
action: receive
channel:
$ref: "#/channels/orders.created"
x-kurkik:
kafka:
operation:
security: []
consumerConfiguration: {}
groupConfiguration: {}
receive_payments.settled:
action: receive
channel:
$ref: "#/channels/payments.settled"
x-kurkik:
kafka:
operation:
security: []
consumerConfiguration: {}
groupConfiguration: {}
send_customers.updated:
action: send
channel:
$ref: "#/channels/customers.updated"
x-kurkik:
kafka:
operation:
security: []
producerConfiguration: {}
send_orders.created:
action: send
channel:
$ref: "#/channels/orders.created"
x-kurkik:
kafka:
operation:
security: []
producerConfiguration: {}
send_payments.settled:
action: send
channel:
$ref: "#/channels/payments.settled"
x-kurkik:
kafka:
operation:
security: []
producerConfiguration: {}

Download source.yaml

How to build this setup yourself

Brokers

Cluster a

Terminal window
kafka-topics.sh --bootstrap-server a-kafka-1:9092 --create --topic orders.created --partitions 3 --replication-factor 1 --config retention.ms=604800000
kafka-topics.sh --bootstrap-server a-kafka-1:9092 --create --topic payments.settled --partitions 3 --replication-factor 1 --config min.insync.replicas=1 --config retention.bytes=10737418240
kafka-topics.sh --bootstrap-server a-kafka-1:9092 --create --topic customers.updated --partitions 3 --replication-factor 1 --config cleanup.policy=compact
api=http://registry-a:8080/apis/ccompat/v7; type='Content-Type: application/vnd.schemaregistry.v1+json' # apicurio/apicurio-registry-mem:2.6.5.Final
curl -X POST -H "$type" "$api/subjects/orders.created-value/versions" --data '{"schemaType":"AVRO","schema":"{\"type\":\"record\",\"name\":\"OrderCreated\",\"namespace\":\"com.shop.orders\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"total\",\"type\":\"long\"}]}"}'
curl -X POST -H "$type" "$api/subjects/payments.settled-value/versions" --data '{"schemaType":"PROTOBUF","schema":"syntax = \"proto3\";\npackage com.shop.payments;\n\nmessage PaymentSettled {\n string id = 1;\n int64 cents = 2;\n}\n"}'
curl -X POST -H "$type" "$api/subjects/customers.updated-value/versions" --data '{"schemaType":"JSON","schema":"{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"title\":\"Customer\",\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"}},\"required\":[\"id\"]}"}'
curl -X POST -H "$type" "$api/subjects/orders.created-value/versions" --data '{"schemaType":"AVRO","schema":"{\"type\":\"record\",\"name\":\"OrderCreated\",\"namespace\":\"com.shop.orders\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"total\",\"type\":\"long\"},{\"name\":\"note\",\"type\":[\"null\",\"string\"],\"default\":null}]}"}'
curl -X POST -H "$type" "$api/subjects/payments.settled-value/versions" --data '{"schemaType":"PROTOBUF","schema":"syntax = \"proto3\";\npackage com.shop.payments;\n\nmessage PaymentSettled {\n string id = 1;\n int64 cents = 2;\n optional string currency = 3;\n}\n"}'
curl -X PUT -H "$type" "$api/config/orders.created-value" --data '{"compatibility":"BACKWARD"}'

Cluster b

Terminal window
kafka-topics.sh --bootstrap-server b-kafka-1:9092 --create --topic orders.created --partitions 3 --replication-factor 1 --config retention.ms=604800000
kafka-topics.sh --bootstrap-server b-kafka-1:9092 --create --topic payments.settled --partitions 3 --replication-factor 1 --config min.insync.replicas=1 --config retention.bytes=10737418240
kafka-topics.sh --bootstrap-server b-kafka-1:9092 --create --topic customers.updated --partitions 3 --replication-factor 1 --config cleanup.policy=compact
api=http://registry-b:8080/apis/ccompat/v7; type='Content-Type: application/vnd.schemaregistry.v1+json' # apicurio/apicurio-registry-mem:2.6.5.Final
curl -X POST -H "$type" "$api/subjects/orders.created-value/versions" --data '{"schemaType":"AVRO","schema":"{\"type\":\"record\",\"name\":\"OrderCreated\",\"namespace\":\"com.shop.orders\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"total\",\"type\":\"long\"}]}"}'
curl -X POST -H "$type" "$api/subjects/payments.settled-value/versions" --data '{"schemaType":"PROTOBUF","schema":"syntax = \"proto3\";\npackage com.shop.payments;\n\nmessage PaymentSettled {\n string id = 1;\n int64 cents = 2;\n}\n"}'
curl -X POST -H "$type" "$api/subjects/customers.updated-value/versions" --data '{"schemaType":"JSON","schema":"{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"title\":\"Customer\",\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"}},\"required\":[\"id\"]}"}'
curl -X POST -H "$type" "$api/subjects/customers.updated-value/versions" --data '{"schemaType":"JSON","schema":"{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"title\":\"Customer\",\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"},\"email\":{\"type\":\"string\"}},\"required\":[\"id\"]}"}'

Sync

Terminal window
kurkik conn add kafka a --bootstrap a-kafka-1:9092 --registry-url http://registry-a:8080 --registry-vendor apicurio
kurkik conn add kafka b --bootstrap b-kafka-1:9092 --registry-url http://registry-b:8080 --registry-vendor apicurio
kurkik kafka export a --acls --groups --stdout > a.yaml # source.yaml
kurkik kafka sync a.yaml b --schemas --overwrite --dry-run # plan.txt (and -o json: plan.json)
kurkik kafka sync a.yaml b --schemas --overwrite --yes # apply.txt, and the rollback: rollback.yaml
kurkik kafka sync revert ~/.local/state/kurkik/sync/b/b-<time>.snapshot.yaml b --force --yes # revert.txt

All flags: kurkik kafka sync · more Apache Kafka sync examples