confluentinc / confluent-kafka-javascript

Confluent's Apache Kafka JavaScript client
https://www.npmjs.com/package/@confluentinc/kafka-javascript
MIT License
59 stars 5 forks source link

[Question] How to know when a consumer is ready? #118

Closed apeloquin-agilysys closed 2 hours ago

apeloquin-agilysys commented 2 hours ago

In KafkaJS we make use of the consumer.group_join event for our application to know a consumer is ready to receive messages.

consumer.on(consumer.events.GROUP_JOIN, (event: ConsumerGroupJoinEvent) => {
  // inform app this consumer is ready
});

Per #38, the on methods don't appear to be on the immediate road map.

About the on methods, we don't plan to implement them yet.

I'm wondering if you have an alternative approach we can use to ascertain consumer readiness?

Originally we were using this:

consumer.assignment().length > 0

Unfortunately, it turns out that when you have a topic with more consumers than partitions, the consumers that don't get a partition also never satisfy this condition.

I see we get log entries:

{
  "message": "Consumer connected",
  "extra": {
    "fac": "BINDING",
    "name": "undefined#consumer-1"
  }
}

...but even if we were to hijack these events with our own Logger, I see no way to tie the name back to the consumers created (in our case we may have dozens).

apeloquin-agilysys commented 2 hours ago

Sorry, I just noticed this very much overlaps with #65.