2016-03-22 18 views
0

okunamadı Bir java Kafka tüketici uygulamaya çalışın. Kafka sunucu sürümünü 0.9 kullanıyorum. Test amaçlı olduğu için tek yapmam gereken tek bir mesaj okumak. iade kayıtlar nesneBir ileti wth java tabanlı Kafka Tüketici

public static ConsumerRecords<String, String> readFromKafka() { 
ConsumerRecords<String, String> records = null; 
try { 
    Properties kafkaProps = new Properties(); 
    kafkaProps.put("bootstrap.servers", "<KAFKA_SERVER_HOST>:9092"); 
    kafkaProps.put("auto.commit.enable", "false"); 
    kafkaProps.put("value.deserializer", StringDeserializer.class.getName()); 
    kafkaProps.put("key.deserializer", StringDeserializer.class.getName()); 
    kafkaProps.put("client.id", "testScore0"); 
    kafkaProps.put("group.id", "testScore1"); 
    kafkaProps.put("auto.offset.reset", "latest"); 

    KafkaConsumer<String, String> consumer = new KafkaConsumer<>(kafkaProps); 
    consumer.subscribe(Arrays.asList("my_topic")); 

    records = consumer.poll(0); 

    } catch (Exception e) { 
    logger.error("Can not read from kafka", e); 
    } 
    return records; 
} 

boş:

enter image description here

Aynı KAFKA_SERVER_HOST bağlanan benim yerel makinede bir komut satırı Kafka tüketici yürütmek ve mesajları olsun.

cevap

1

değişim 0'dan büyük bir şey için

records = consumer.poll(0); 

üzerinde anket süresi, deneyin 100.

records = consumer.poll(100); 
İlgili konular