0

I want to consume avro messages and deserialize them without using the Confluent schema registry. I have the schema locally. So, for that, I followed this https://medium.com/@mailshine/apache-avro-quick-example-in-kafka-7b2909396c02 for Consumer part only. Now, I want to configure this deserializer in the application.properties file (the Spring boot way). I tried adding spring.kafka.consumer.value-deserializer=com.example.AvroDeserializer But this results in error saying "Could not find a public no-argument constructor for com.example.AvroDeserializer". Is there any way to call the constructor with argument from application.properties configuration. Or Do I need to configure this in Code instead of properties?

Thanks in advance!!

1 Answer 1

1

You can do it using properties, but you have to do it via the configure method (with a no-arg constructor) - this is because Kafka instantiates the deserializer, not Spring.

See the org.springframework.kafka.support.serializer.JsonDeserializer source code for an example.

Otherwise, you can just inject your Deserializer into the consumer factory...

@Bean
MyDeserializer(DefaultKafkaConsumerFactory<String, Foo> factory) {
    MyDeserializer<Foo> deser = new MyDeserializer<>(...);
    factory.setValueDeserializer(deser);
    return deser;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.