Days ago I was to get start with the newest Kafka document to learn about Kafka. But I meet some problem when I try to use the new Consumer API. I'd done the job with following steps:

1. Add a new dependency


2. Add configurations

Latest documents did not contains such configurable things, it took me a while to figure out how KafkaProducer works, and I used some similar configurations to set the config map

    Map<String, Object> config = new HashMap<String, Object>();
    config.put(ConsumerConfig.GROUP_ID_CONFIG, "test");
    config.put(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY, "range");

3. Use KafkaConsumer API

KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(config);

However, when I try to poll message from the broker, I got nothing but null:

Map<String, ConsumerRecords<String, String>> records = consumer.poll(0);
if (records != null)

And then I know what's wrong with the consumer after I checked the source code:

public Map<String, ConsumerRecords<K,V>> poll(long timeout) {
    // TODO Auto-generated method stub
    return null;

To make matters worse, I couldnot find any other useful information about the 0.8.2 API, since all usages about Kafka were not compatible with the latest version. I had to ask a question on SO, wishing to get some helpful advice.

Unfortunately, I could only get a bad news after ten days waiting:

--- @habsq ---
The new KafkaConsumer API will only be available in 0.8.3 Apparently there are some implementation in the trunk, although I have no clue about the state. For the time being I'm using the old consumer implementation.

Oops, documents could also lie, that's so sad (x﹏x)


comments powered by Disqus