Let's say you have 10 partitions in the topic for which you are doing subscribe after creating the consumer object. When you create the first consumer object and start to perform the poll
operation, All the 10 partitions will be assigned to this consumer object.
When you create the second consumer object, the consumer group co-ordinator would realize that some other consumer has joined in the group and hence a rebalance would trigger. Depending on the partition assignment strategy used, some of the partitions would be assigned to the second consumer. In the default case, 5 of the partition would be taken from the first consumer and assigned to the second consumer. Now each consumer will have 5 partitions each.
So the partition structure would change after creating the second consumer and after the poll operation from the second consumer.
EDIT1:
If you do the .assignment()
on both the consumer, after you have started to consume from both the consumer. You will get the same result.
EDIT2:: If you have two different consumer group id, and if there is only 1 consumer in both the group, then yeah the partition structure would be the same.
If you have multiple consumers under a consumer group, but both of them have the same number of consumers in the consumer group(say 3 consumer in each consumer group) and the consumer partition strategy used is also the same, then the partition structure would be same.
If you have multiple numbers of consumers in both the group but different numbers in each consumer group(say first consumer group has 2 consumers and second consumer group has 3 consumers), then as you can guess the partition structure would be different.
saved offset
– Aditya Rewari