Kafka consumer subscribers -- member assignments being lost (nodejs) #6720
Replies: 1 comment
-
There is no special heartbeat protocol. The heartbeats are part of the Kafka communication between the client and the broker(s). So there is nothing special done to route the heartbeats and if you client can connect, the general routing is fine. So I think that apart of the suggestions regarding the client code mentioned on SO, you would need to look into the general issues you might have with your cluster ... lack of resources, unstable network etc. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Synopsis
We have a subscriber that responds to events on 5 topics with a single consumer-group, each with a single partition. When firing events into these topics, we see our code handling the first two events, then nothing. When we check, on startup, the consumer group has 5 member assignments, but after handling the 2nd event all of the member assignments disappear.
Code
Here is the subscription code:
To invoke this we use:
Output
When we run the consumer we see a log message from kafka:
Showing that we have successfully subscribed to 5 topics. We expect to see those 5 events in the order listed above. However, after the
approve
event, no other events are handled, and when we look at kafka all the members have gone. There is no exception or other log that would suggest an error in our code.Incidentally, our handlers run very fast. They make a local HTTP call to another container in the same pod that updates a single field in a single document in MongoDB. Typically the handlers run and respond in < 500ms.
Suspicions
As JavaTechnical suggests in the answer below, we believe that this may be related to the heartbeat mechanism. The kafka logs show this:
We're using strimzi to run kafka in k8s, and we see in the logs:
We think that the consumption of the first two messages is probably just luck -- we're getting them before the session-timeout is triggered by the lack of heartbeats.
What have we tried?
But that isn't helping.
Kafkajs documentation says that the
eachMessage
structure in the consumer runner should automate the heartbeats, but given the nature of the error we've also tried explicitly passing the heartbeat function to the handler and manually invoking it, also to no avail.We've also tried extending the timeouts and heartbeat intervals using strimzi, but our attempts to do so failed (they crashed strimzi) so we've backed out of that.
Question
Given all of this, we suspect that the kafkajs heartbeats are not making it through to kafka in k8s. Our question is, how do we ensure that this works? I would expect strimzi to have configured a route for the heartbeat to hit the broker (?). We can see the group memberships reducing to zero in the kafka logs, but we don't know why the heartbeats aren't making it through. We have nothing weird in our code -- our handlers are normal pods (ish -- actually, they are sidecars that pass the events onto the main container via HTTP).
Versions
We're using the latest strimzi, kafka, and kafkajs in node 17+.
Reference:
We have also raised this question on stackoverflow
https://stackoverflow.com/questions/71953924/kafka-consumer-subscribers-member-assignments-being-lost-nodejs
Beta Was this translation helpful? Give feedback.
All reactions