-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OnPartitionsAssigned & OnPartitionsRevoked Not Invoked #434
Comments
what you describe, as I read it, should work so I think i'm miss-understanding. I assume your topic has more than one partition? please provide a complete minimal program that demonstrates the problem and I'll take a look at that. |
Hi, our topic has a single partition replicated through 3 brokers. How to use the code? Here is code that does mentioned behavior:
Creation of config:
Consumer:
|
messages in a single partition are never split between multiple consumers. each partition will be read by exactly one consumer and each consumer will read from zero or more partitions. |
@mhowlett Thanks for your reply. What we experience right now is, that when given code is being executed with Subscribe, then balancing works, only one consumer gets the messages others are idling since there is no other partition. And this balancing is being done via help of events (OnPartitionsAssigned & OnPartitionsRevoked) being invoked. However, if we execute same code with assign in that case we cannot rebalance and both of the consumers are getting same messages even when they are on the same consumer.group. |
Subscribe() joins the consumer group and balances available partitions across the joined members, the assignment for each member is then Assign():ed. Assign() simply starts fetching the given partitions, it does not perform any correlation with other consumers. |
@edenhill Ok, thanks for elaboration. However is there a way to get these events invoked? Since we perform range consumption of topics so we start consuming from provided offset and it is only available via Assign. |
You can do that by transforming the TopicPartition list passed to you in OnPartitionsAssigned into a TopicPartitionOffset list with your choice of start offset which you then pass to Assign(). This is for the underlying C client, but explains its use: |
@edenhill Thanks a bunch. I done my digging in the code but c client wasn't an easy beast to understand. I'll take a look, thanks for your time. |
This is a good start: https://docs.confluent.io/current/clients/consumer.html |
Happy to hear you got it sorted out! |
Description
When assigning topics via
Assign
method neitherOnPartitionsAssigned
norOnPartitionsRevoked
is being called when additional consumer is connected. When I useSubscribe
method when it calls these methods.Since we want to perform start consuming from different offsets we are using assign, since with subscribe you cannot set offset to start consuming from.
Odd part:
When you perform manual Assign OnPartitionsAssigned event then for some reason it actually manages to call these events further down the lifetime of this consumer.
How can we use
Assign
method and as well get notified when new consumer of sameconsumer.group
is connected to cluster?How to reproduce
When initializing consumer one should use
consumer.Assign(new[] { new TopicPartition(topic, 0) });
when you create another instance with same config you do not get events (OnPartitionsAssigned & OnPartitionsRevoked) called to handle balancing.Checklist
Please provide the following information:
"bootstrap.servers", "brokers"
"enable.auto.commit", "false"
"auto.offset.reset", "earliest"
The text was updated successfully, but these errors were encountered: