Calling `consumer.subscribe()` is a local call. Only when you call `consumer.poll()` the consumer will connect to the broker to get its assignment. Thus, it's save to call `poll()` directly.
`assignment()` will return the assignment only after the first `poll()`
call.
-Matthias
On 1/23/19 9:00 AM, chinchu chinchu wrote:
> Hello,
> I have subscribed to a kafka topic as below . I need to run some logic
> only after the consumer has been assigned a partition .How ever
> consumer.assignment() comes back as an empty set no matter how long I wait
> . If I do not have the while loop and then do a consumer.poll() I do get
> the records from the topic.Can any one tell me why this is happening ?
>
> consumer.subscribe(topics);
> consumer.
>
> Set<TopicPartition> assigned=Collections.emptySet();
> while(isAssigned)
> {
> assigned = consumer.assignment();
> if(!assigned.isEmpty()) {
> isAssigned= false;
> }
> }
>
> Thanks,
>
> On Tue, Jan 22, 2019 at 2:14 PM chinchu chinchu <[email protected]>
> wrote:
>
>> Hello,
>> I have subscribed to a kafka topic as below . I need to run some logic
>> only after the consumer has been assigned a partition .How ever
>> consumer.assignment() comes back as an empty set no matter how long I wait
>> . If I do not have the while loop and then do a consumer.poll() I do get
>> the records from the topic.Can any one tell me why this is happening ?
>>
>> consumer.subscribe(topics);
>> consumer.
>>
>> Set<TopicPartition> assigned=Collections.emptySet();
>> while(isAssigned)
>> {
>> assigned = consumer.assignment();
>> if(!assigned.isEmpty()) {
>> isAssigned= false;
>> }
>> }
>>
>> Thanks,
>> Chinchu
>>
>
signature.asc
Description: OpenPGP digital signature
