Bird
0
0

Find the bug in this Kafka controller election monitoring code snippet:

medium📝 Debug Q7 of 15
Kafka - Cluster Architecture

Find the bug in this Kafka controller election monitoring code snippet:

var controllerFuture = adminClient.describeCluster().controller();
var controllerId = controllerFuture.id().get();
System.out.println("Controller ID: " + controllerId);
AcontrollerFuture is a KafkaFuture<Node>, id() must be called after get()
Bid() returns a Future, so get() is called twice incorrectly
CMissing call to get() on controllerFuture before id()
DNo bug; code works as expected
Step-by-Step Solution
Solution:
  1. Step 1: Understand KafkaFuture chaining

    describeCluster().controller() returns KafkaFuture<Node> which must be resolved first.
  2. Step 2: Identify correct method call order

    Must call get() on controllerFuture to get Node, then call id() on Node.
  3. Final Answer:

    Missing call to get() on controllerFuture before id() -> Option C
  4. Quick Check:

    Call get() on future before accessing id() [OK]
Quick Trick: Call get() on KafkaFuture before accessing Node methods [OK]
Common Mistakes:
  • Calling id() before get() on KafkaFuture
  • Assuming id() returns a Future
  • Not resolving futures properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes