I have been wondering about the need for an Avro Schema Registry when consuming messages from a Kafka topic using a statically typed language, like Java. I'm consuming messages from a Kafka topic setup like this:
Properties props = new Properties();
props.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, String.join(",", kafkaProperties.getServers()));
props.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName());
props.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, KafkaAvroDeserializer.class.getName());
props.setProperty(KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG, kafkaProperties.getSchemaRegistryUrl());
KafkaConsumer<byte[], FooClass> kafkaConsumer = new KafkaConsumer<>(props);;
In my project I have .avsc
files that define the schema for FooClass class. I have also configured the avro-maven-plugin
to generate the class FooClass
for me at build time.
Why do I still need to specify a Schema Registry URL? Isn't my consumer able to deserialize the values of my Kafka messages using the .avsc
file in my project?