0
0
Kafkadevops~10 mins

Why SDK integration enables applications in Kafka - Test Your Understanding

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

Complete the code to create a Kafka producer.

Kafka
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers=[1])
Drag options to blanks, or click blank then click option'
A'127.0.0.1:2181'
B'localhost:9092'
C'kafka:2181'
D'localhost:2181'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ZooKeeper port instead of Kafka broker port.
2fill in blank
medium

Complete the code to send a message to a Kafka topic.

Kafka
producer.send([1], b'Hello Kafka')
Drag options to blanks, or click blank then click option'
A'my_topic'
B123
Cb'my_topic'
Dtopic
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a number or bytes instead of a string as topic name.
3fill in blank
hard

Fix the error in the code to properly flush the Kafka producer.

Kafka
producer.[1]()
Drag options to blanks, or click blank then click option'
Astart
Bsend
Cclose
Dflush
Attempts:
3 left
💡 Hint
Common Mistakes
Using close() instead of flush(), which stops the producer.
4fill in blank
hard

Fill both blanks to create a Kafka consumer that subscribes to a topic.

Kafka
from kafka import KafkaConsumer
consumer = KafkaConsumer([1], bootstrap_servers=[2])
Drag options to blanks, or click blank then click option'
A'my_topic'
B'localhost:9092'
C'localhost:2181'
D'my_group'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ZooKeeper port 2181 instead of Kafka broker port 9092.
5fill in blank
hard

Fill all three blanks to create a Kafka producer that sends a message and flushes it.

Kafka
producer = KafkaProducer(bootstrap_servers=[1])
producer.send([2], b'Hello')
producer.[3]()
Drag options to blanks, or click blank then click option'
A'localhost:9092'
B'test_topic'
Cflush
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using close() instead of flush(), or wrong port for bootstrap_servers.