Advanced Patterns · Advanced
Avro Serialization with Schema Registry
Avro + Schema Registry is the production standard for strong typing, schema evolution, and compact wire format. Spring Kafka integrates seamlessly via ConfluentKafkaAvroSerializer.
spring:
kafka:
producer:
value-serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
properties:
schema.registry.url: http://schema-registry:8081
auto.register.schemas: true
use.latest.version: false
consumer:
value-deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer
properties:
schema.registry.url: http://schema-registry:8081
specific.avro.reader: true # Deserialize to generated Java classes{
"type": "record",
"name": "OrderEvent",
"namespace": "com.example.events",
"fields": [
{ "name": "orderId", "type": "string" },
{ "name": "customerId", "type": "string" },
{ "name": "status", "type": "string" },
{ "name": "amount", "type": "double" },
{ "name": "timestamp", "type": "long", "logicalType": "timestamp-millis" },
{ "name": "metadata", "type": ["null", "string"], "default": null }
]
}