I found a better approach:

final List<TopicPartition> partitions = consumer.partitionsFor(TOPIC_NAME)
                                                .stream()
                                                .map(part -> new
TopicPartition(TOPIC_NAME, part.partition()))
                                                .collect(Collectors.toList());

consumer.assign(partitions);

consumer.seekToBeginning(consumer.assignment());


Best regards,
Behrang Saeedzadeh

On 15 December 2017 at 14:08, Behrang Saeedzadeh <behran...@gmail.com>
wrote:

> Hi
>
> In my consumer app, in order to start consuming records from the beginning
> of all partitions of a given Kafka topic, I first have to issue a poll to
> make sure partitions are assigned to my consumer:
>
> consumer.poll(1000);
> consumer.seekToBeginning(consumer.assignment());
>
> Is there an alternative approach available to assign partitions to the
> consumer that doesn't require issuing an initial poll?
>
> Best regards,
> Behrang Saeedzadeh
>

Reply via email to