This repo shows Confluent Data Contracts in action, following the instructions detailed in this blog post
- Docker (latest versions bundled with former Docker Compose)
- kafka-avro-console-producer CLI
- kafka-avro-console-consumer CLI
- jq CLI for some formatting
docker compose up -d
docker compose logs -f
jq -n --rawfile schema order.avsc '{schema: $schema}' |
curl -s http://localhost:8081/subjects/orders-value/versions \
--header "Content-Type: application/json" --header "Accept: application/json" \
--data @-
curl -s http://localhost:8081/subjects/orders-value/versions \
--header "Content-Type: application/json" --header "Accept: application/json" \
--data "@order_metadata.json"
curl -s http://localhost:8081/subjects/orders-value/versions \
--header "Content-Type: application/json" --header "Accept: application/json" \
--data @order_ruleset.json
curl -s http://localhost:8081/subjects/orders-value/versions \
--header "Content-Type: application/json" --header "Accept: application/json" \
--data @order_ruleset_disabled.json
From the output, of the previous commands, we capture the ID of the schema we want to use.
Assumming that the last evolution was registered with ID = 3, we can start consumers and producers respectively
kafka-avro-console-consumer \
--topic orders \
--bootstrap-server localhost:9092
For the producer we specify the ID=3, if your ID is different, update it accordingly
kafka-avro-console-producer \
--topic orders \
--broker-list localhost:9092 \
--property value.schema.id=3
{"orderId": 1, "customerId": 2, "totalPriceCents": 12000, "state": "Pending", "timestamp": 1693591356 }
docker compose down -v