Bird
0
0

Given the following code snippet, what will be the output if the current controller broker ID is 3?

medium📝 Predict Output Q4 of 15
Kafka - Cluster Architecture

Given the following code snippet, what will be the output if the current controller broker ID is 3?

var controllerId = adminClient.describeCluster().controller().get().id();
System.out.println(controllerId);
Anull
B3
C0
DException thrown
Step-by-Step Solution
Solution:
  1. Step 1: Understand the code behavior

    The code calls describeCluster().controller().get().id() which returns the controller broker ID synchronously.
  2. Step 2: Given controller ID is 3, output is 3

    Since controller ID is 3, the printed output will be 3.
  3. Final Answer:

    3 -> Option B
  4. Quick Check:

    Output = controller ID value = 3 [OK]
Quick Trick: describeCluster().controller().get().id() returns controller ID synchronously [OK]
Common Mistakes:
  • Expecting null if controller exists
  • Assuming default 0 if no controller
  • Thinking code throws exception without error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes