0
0
Kafkadevops~10 mins

Broker nodes in Kafka - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the broker address in the Kafka producer configuration.

Kafka
producer = KafkaProducer(bootstrap_servers='[1]')
Drag options to blanks, or click blank then click option'
A127.0.0.1:2181
Blocalhost:9092
Ckafka-broker:2181
Dbroker-node:2183
Attempts:
3 left
💡 Hint
Common Mistakes
Using Zookeeper port 2181 instead of broker port 9092.
Using IP without port number.
2fill in blank
medium

Complete the code to list all broker nodes in a Kafka cluster using the AdminClient.

Kafka
admin_client = AdminClient({'bootstrap.servers': '[1]'})
brokers = admin_client.describe_cluster().brokers
Drag options to blanks, or click blank then click option'
Alocalhost:9092
Bbroker1:2183
Czookeeper:2181
Dkafka:9093
Attempts:
3 left
💡 Hint
Common Mistakes
Using Zookeeper address instead of broker address.
Using wrong port number.
3fill in blank
hard

Fix the error in the code to correctly connect to a Kafka broker node.

Kafka
consumer = KafkaConsumer('my_topic', bootstrap_servers='[1]')
Drag options to blanks, or click blank then click option'
Alocalhost:9092
Bzookeeper:9092
Cbroker-node:2181
Dkafka:2183
Attempts:
3 left
💡 Hint
Common Mistakes
Using Zookeeper address or port.
Using incorrect port number.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps broker IDs to their hostnames.

Kafka
broker_map = {broker.[1]: broker.[2] for broker in cluster.brokers()}
Drag options to blanks, or click blank then click option'
Aid
Bhost
Cport
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using port or name instead of host.
Mixing up id and host.
5fill in blank
hard

Fill all three blanks to filter brokers with port greater than 9092 and create a dictionary of their IDs and hosts.

Kafka
filtered_brokers = {broker.[1]: broker.[2] for broker in cluster.brokers() if broker.[3] > 9092}
Drag options to blanks, or click blank then click option'
Aid
Bhost
Cport
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Filtering by id or host instead of port.
Mixing up keys and values in the dictionary.