tsar2512 tsar2512 - 1 year ago 115
Java Question

Kafka Consumer Properties to read from the maximum offset

I have written a Java Kafka Consumer. I would like to make sure how to explicitly ensure that once the Kafka Consumer is started it only reads the messages which are sent by the producer from that time onwards i.e. it should not read any messages which have already been sent by the producer to Kafka. Can anyone explain how to ensure this? :

Here is a snippet of the properties I use

Properties properties = new Properties();
properties.put("zookeeper.connect", zookeeperHost);
properties.put("group.id", group);
ConsumerConfig consumerConfig = new ConsumerConfig(properties);
consumerConnector = Consumer.createJavaConsumerConnector(consumerConfig);

UPDATE Sept14:

I am using the following properties, it seems that the consumer still reads from the beginning at times, can someone tell me what's wrong now?

I am using Kafka Version 0.8.2


Answer Source

Based on answers above, it seems that the correct mechanism is as follows for setting properties of the consumer:


This ensures reading from the maximum offset

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download