Before you can seek() , you first need to subscribe() to go to the section or assign() of the topic section for the consumer. Also keep in mind that subscribe() and assign() lazy - so you also need to make a βdummy callβ before poll() before you can use seek() .
If you use subscribe() , you use group control: in this way, you can start several users using the same group.id , and all sections of the section will be distributed evenly among all users in the group automatically (each section will get assigned to one to the consumer in the group).
If you want to read specific sections, you need to use manual assignment via assign() . This allows you to complete any task you want.
Btw: KafkaConsumer has a very long detailed JavaDoc class, including examples. Worth reading it.
source share