0
0
Kafkadevops~15 mins

Broker nodes in Kafka - Mini Project: Build & Apply

Choose your learning style9 modes available
Broker Nodes in Kafka
📖 Scenario: You are setting up a Kafka cluster to handle messages for a small online store. Each Kafka broker node stores and manages messages. You want to create a simple list of broker nodes with their IDs and hostnames.
🎯 Goal: Create a dictionary representing Kafka broker nodes with their IDs as keys and hostnames as values. Then filter the brokers to find those with IDs greater than a certain threshold.
📋 What You'll Learn
Create a dictionary called brokers with broker IDs as keys and hostnames as values
Create a variable called threshold with the value 2
Create a new dictionary called filtered_brokers that includes only brokers with IDs greater than threshold
Print the filtered_brokers dictionary
💡 Why This Matters
🌍 Real World
Kafka brokers are servers that store and manage message data. Managing broker nodes helps in scaling and maintaining message systems.
💼 Career
Understanding how to work with broker nodes and filter them is useful for roles in data engineering, backend development, and system administration involving Kafka.
Progress0 / 4 steps
1
Create the initial broker nodes dictionary
Create a dictionary called brokers with these exact entries: 1: 'broker1.example.com', 2: 'broker2.example.com', 3: 'broker3.example.com', 4: 'broker4.example.com'
Kafka
Need a hint?

Use curly braces {} to create a dictionary with integer keys and string values.

2
Set the threshold for filtering brokers
Create a variable called threshold and set it to 2
Kafka
Need a hint?

Just assign the number 2 to the variable threshold.

3
Filter brokers with IDs greater than threshold
Create a new dictionary called filtered_brokers that includes only the brokers from brokers where the broker ID is greater than threshold. Use a dictionary comprehension with broker_id and hostname as variables.
Kafka
Need a hint?

Use a dictionary comprehension with for broker_id, hostname in brokers.items() and an if condition.

4
Print the filtered brokers
Write a print statement to display the filtered_brokers dictionary
Kafka
Need a hint?

Use print(filtered_brokers) to show the result.