Hi,
Using Kafka Source in Akka Streams Kafka, I am trying to deserialize an 
Avro object using KafkaAvroDeserializer that is created using avro-tools 
library.

If I use confluent Kafka Consumer, I can deserialize it like this:

def consumerProperties() = {
  val props = new Properties
  props.put("bootstrap.servers", kafkaServer)
  props.put("group.id", UUID.randomUUID().toString)
  props.put("auto.commit.enable", "false")
  props.put("auto.offset.reset", "earliest")
  props.put("schema.registry.url", schemaUrl)
  props.put(KafkaAvroDeserializerConfig.SPECIFIC_AVRO_READER_CONFIG, "true")
  props.put("key.deserializer", 
"org.apache.kafka.common.serialization.StringDeserializer")
  props.put("value.deserializer", 
"io.confluent.kafka.serializers.KafkaAvroDeserializer")
  props
}


def consume(): Unit ={

  val consumer = new KafkaConsumer[String, Person](consumerProperties)
 consumer.subscribe(Collections.singletonList(topic))

  while(true){

    val records : ConsumerRecords[String, Person] =consumer.poll(100)
    records.forEach(i => println(i.value().getName))
}
}



But I am unable to deserialize using Kafka source in Akka Streams Kafka.

The consumer settings is of type ConsumerSettings[String, AnyRef], and I think 
I need to somehow change it to ConsumerSettings[String, Person]



val consumerSettings  = ConsumerSettings(system,new StringDeserializer, new 
KafkaAvroDeserializer)
  .withBootstrapServers(kafkaServer)
  .withGroupId(UUID.randomUUID().toString)
  .withProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest")
  .withProperty("schema.registry.url", schemaUrl)
  .withProperty(KafkaAvroDeserializerConfig.SPECIFIC_AVRO_READER_CONFIG, "true")
  .withProperty("key.deserializer", 
"org.apache.kafka.common.serialization.StringDeserializer")
  .withProperty("value.deserializer", 
"io.confluent.kafka.serializers.KafkaAvroDeserializer")

val  subscriptions = Subscriptions.topics(topic)
val output  = Consumer.plainSource(consumerSettings,subscriptions)
output



 


-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to