0
0
Kafkadevops~10 mins

Why producers publish data 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 send a message to a Kafka topic.

Kafka
producer.send('[1]', b'Hello World')
Drag options to blanks, or click blank then click option'
Amy_topic
Bconsumer_group
Cbroker_list
Dpartition_key
Attempts:
3 left
💡 Hint
Common Mistakes
Using consumer group or broker list instead of topic name.
2fill in blank
medium

Complete the code to create a Kafka producer with the correct bootstrap server.

Kafka
producer = KafkaProducer(bootstrap_servers='[1]')
Drag options to blanks, or click blank then click option'
Alocalhost:9092
Bconsumer_group:9092
Ctopic_name:9092
Dpartition_key:9092
Attempts:
3 left
💡 Hint
Common Mistakes
Using consumer group or topic name instead of broker address.
3fill in blank
hard

Fix the error in the code to publish a message with a key.

Kafka
producer.send('my_topic', key=[1], value=b'Hello')
Drag options to blanks, or click blank then click option'
A'key1'
Bkey1
Cb'key1'
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using string keys without bytes prefix.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

Kafka
{word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Bword > 3
Clen(word) > 3
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value or wrong condition syntax.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values only if value is positive.

Kafka
result = [1]: [2] for [3], [2] in data.items() if [2] > 0
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or not converting keys to uppercase.