Use the assign
method instead of subscribe
method
public void sample() {
KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(properties);
TopicPartition partition = new TopicPartition("some-topic", 0);
consumer.assign(Arrays.asList(partition));
consumer.seek(partition, 0);
while (true) {
final ConsumerRecords<Long, String> consumerRecords = consumer.poll(1000);
}
}
As far as I know, it is not necessary to specify the consumer group when you are using the assign method instead of subscribe method, in
the Consumer properties, and hence probably will ignore those parameters (enable.auto.commit,auto.offset.reset). Use the assign method and seek only for debugging or testing purposes.
There is also another method called offsetsForTimes to get the desired offset to seek.