Cannot print Kafka Avro decoded message

26 views
Skip to first unread message

Karthik Jayaraman

unread,
Aug 25, 2017, 2:04:44 AM8/25/17
to Confluent Platform
I have a legacy C++ based system which spits out binary encoded Avro data that supports confluent Avro schema registry format. In my Java application, I successfully deserialized the message using KafkaAvroDeserializer class but could not print out the message.

private void consumeAvroData(){
   
String group = "group1";
   
Properties props = new Properties();
    props
.put("bootstrap.servers", "http://1.2.3.4:9092");
    props
.put("group.id", group);
    props
.put("enable.auto.commit", "true");
    props
.put("auto.commit.interval.ms", "1000");
    props
.put("session.timeout.ms", "30000");
    props
.put("key.deserializer", LongDeserializer.class.getName());
    props
.put("value.deserializer", KafkaAvroDeserializer.class.getName());
   
// props.put(KafkaAvroDeserializerConfig.SPECIFIC_AVRO_READER_CONFIG,"false");
    props
.put("schema.registry.url","http://1.2.3.4:8081");
   
KafkaConsumer<String, GenericRecord> consumer = new KafkaConsumer<String, GenericRecord>(props);

    consumer
.subscribe(Arrays.asList(TOPIC_NAME));
   
System.out.println("Subscribed to topic " + TOPIC_NAME);

   
while (true) {
       
ConsumerRecords<String, GenericRecord> records = consumer.poll(100);
       
for (ConsumerRecord<String, GenericRecord> record : records)
       
{
           
System.out.printf("value = %s\n",record.value());
       
}
   
}

The output I get is 

{"value":"�"}

Why is that I cannot print the deserialized data ? Any help appreciated ! 

Pranav Prakash

unread,
Sep 2, 2017, 12:03:27 PM9/2/17
to Confluent Platform
I am fairly new to this ecosystem, but I may have a reason for this. The value() would still return you binary value. You would have to convert it into a String or a HashMap (depending on what your value actually is) and then you should be able to see the values.
Reply all
Reply to author
Forward
0 new messages