Exception in thread "main" java.lang.IllegalArgumentException: You can only check the position for partitions assigned to this consumer

Viewed 2339

For the following code I used

 KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(props);
 consumer.subscribe(Arrays.asList(TOPIC));
 TopicPartition partition = new TopicPartition(TOPIC, 0);
 System.out.println(consumer.position(partition));

I received the error like the "You can only check the position for partitions assigned to this consumer.", what's wrong with the above code?

1 Answers

When partitions are automatically assigned a call to poll after subscribe will trigger a rebalance and partition assignment. You are missing that poll call.

Related