1
1
package com.omprakash.springbootplayground.kafka
2
2
3
- import com.omprakash.springbootplayground.kafka.message.BookCreated
3
+ import io.confluent.kafka.serializers.KafkaAvroDeserializer
4
+ import org.apache.avro.generic.GenericRecord
4
5
import org.apache.kafka.clients.consumer.ConsumerConfig.*
5
6
import org.apache.kafka.common.serialization.StringDeserializer
6
7
import org.springframework.boot.autoconfigure.kafka.KafkaProperties
@@ -18,19 +19,20 @@ object GROUP_ID {
18
19
@Configuration
19
20
class ConsumerConfig (val kafkaProperties : KafkaProperties ) {
20
21
@Bean
21
- fun consumerFactory (): ConsumerFactory <String , BookCreated > {
22
- val props = mapOf<String , Any >(
22
+ fun consumerFactory (): ConsumerFactory <String , GenericRecord > {
23
+ val props = mapOf<String , Any >(
23
24
BOOTSTRAP_SERVERS_CONFIG to kafkaProperties.bootstrapServers,
24
25
KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer ::class .java,
25
- VALUE_DESERIALIZER_CLASS_CONFIG to JsonDeserializer ::class .java,
26
+ VALUE_DESERIALIZER_CLASS_CONFIG to KafkaAvroDeserializer ::class .java,
27
+ " schema.registry.url" to " http://localhost:8081" ,
26
28
JsonDeserializer .TRUSTED_PACKAGES to " *"
27
29
)
28
30
return DefaultKafkaConsumerFactory (props)
29
31
}
30
32
31
33
@Bean
32
- fun bookCreatedKafkaListenerContainerFactory (): ConcurrentKafkaListenerContainerFactory <String , BookCreated > {
33
- return ConcurrentKafkaListenerContainerFactory <String , BookCreated >().apply {
34
+ fun bookCreatedKafkaListenerContainerFactory (): ConcurrentKafkaListenerContainerFactory <String , GenericRecord > {
35
+ return ConcurrentKafkaListenerContainerFactory <String , GenericRecord >().apply {
34
36
consumerFactory = consumerFactory()
35
37
}
36
38
}
0 commit comments