0
0
Kafkadevops~30 mins

Controller broker in Kafka - Mini Project: Build & Apply

Choose your learning style9 modes available
Controller Broker Status Checker with Kafka
📖 Scenario: You are working with Apache Kafka, a system that helps send messages between different parts of a program. One important part is the controller broker, which manages how messages flow and keeps everything running smoothly.In this project, you will write a simple Python program to check which broker is the controller in a Kafka cluster. This helps you understand how Kafka manages its controllers.
🎯 Goal: Build a Python program that connects to a Kafka cluster, finds the controller broker ID, and prints it out.
📋 What You'll Learn
Create a dictionary called brokers with broker IDs as keys and their hostnames as values: 1: 'broker1.example.com', 2: 'broker2.example.com', 3: 'broker3.example.com'
Create a variable called controller_id and set it to 2
Use a for loop with variables broker_id and host to iterate over brokers.items() and find the controller broker
Print the message "Controller broker is ID {controller_id} at {host}" using an f-string
💡 Why This Matters
🌍 Real World
In real Kafka clusters, knowing which broker is the controller helps in monitoring and troubleshooting message flow and cluster health.
💼 Career
Understanding controller brokers is useful for roles like DevOps engineers, system administrators, and backend developers working with distributed systems and message queues.
Progress0 / 4 steps
1
Create the brokers dictionary
Create a dictionary called brokers with these exact entries: 1: 'broker1.example.com', 2: 'broker2.example.com', 3: 'broker3.example.com'
Kafka
Need a hint?

Use curly braces {} to create a dictionary with keys and values separated by colons.

2
Set the controller broker ID
Create a variable called controller_id and set it to 2
Kafka
Need a hint?

Just assign the number 2 to the variable controller_id.

3
Find the controller broker host
Use a for loop with variables broker_id and host to iterate over brokers.items(). Inside the loop, check if broker_id equals controller_id. If yes, assign host to a variable called controller_host
Kafka
Need a hint?

Use for broker_id, host in brokers.items(): to loop. Then use if broker_id == controller_id: to check. Assign host to controller_host.

4
Print the controller broker information
Write a print statement using an f-string to display: "Controller broker is ID {controller_id} at {controller_host}"
Kafka
Need a hint?

Use print(f"Controller broker is ID {controller_id} at {controller_host}") to show the message.