Bird
0
0

Given the following code snippet using Kafka AdminClient in Java, what will controllerId hold after execution?

medium📝 Predict Output Q13 of 15
Kafka - Cluster Architecture

Given the following code snippet using Kafka AdminClient in Java, what will controllerId hold after execution?

AdminClient admin = AdminClient.create(props);
Node controller = admin.describeCluster().controller().get();
int controllerId = controller.id();
admin.close();
AThe total number of brokers in the cluster
BThe topic partition count
CThe port number of the controller broker
DThe broker ID of the current controller broker
Step-by-Step Solution
Solution:
  1. Step 1: Analyze AdminClient describeCluster method

    The describeCluster().controller() returns the current controller broker as a Node object.
  2. Step 2: Understand Node.id()

    The id() method returns the broker ID of that Node, which is the controller broker's ID.
  3. Final Answer:

    The broker ID of the current controller broker -> Option D
  4. Quick Check:

    controller().id() = controller broker ID [OK]
Quick Trick: controller().id() returns controller broker's ID [OK]
Common Mistakes:
  • Confusing controller ID with number of brokers
  • Thinking it returns port or partition count
  • Ignoring the blocking get() call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes