Bird
0
0

Which of the following is the correct way to listen for rebalance events in Kafka consumer code?

easy📝 Syntax Q12 of 15
Kafka - Consumer Groups
Which of the following is the correct way to listen for rebalance events in Kafka consumer code?
Aconsumer.subscribe(topics, new ConsumerRebalanceListener() {...})
Bconsumer.on('rebalance', callback)
Cconsumer.addRebalanceListener(callback)
Dconsumer.listenRebalance(callback)
Step-by-Step Solution
Solution:
  1. Step 1: Recall Kafka consumer API

    Kafka's Java consumer uses subscribe with a ConsumerRebalanceListener to handle rebalance events.
  2. Step 2: Match correct syntax

    Only consumer.subscribe(topics, new ConsumerRebalanceListener() {...}) shows the correct method signature for rebalance listener.
  3. Final Answer:

    consumer.subscribe(topics, new ConsumerRebalanceListener() {...}) -> Option A
  4. Quick Check:

    Use subscribe with ConsumerRebalanceListener [OK]
Quick Trick: Use subscribe with ConsumerRebalanceListener for rebalance [OK]
Common Mistakes:
  • Using non-existent methods like on or addRebalanceListener
  • Confusing event listeners with other APIs
  • Missing the listener parameter in subscribe

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes