0
0
Kafkadevops~10 mins

First message (produce and consume) 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 produce a message to the Kafka topic.

Kafka
producer.send('[1]', b'Hello Kafka!')
Drag options to blanks, or click blank then click option'
Amessages
Bmy_topic
Ckafka_topic
Dtopic1
Attempts:
3 left
💡 Hint
Common Mistakes
Using a topic name that is not defined or different from the example.
Forgetting to put the topic name as a string.
2fill in blank
medium

Complete the code to consume a message from the Kafka topic.

Kafka
for message in consumer.[1]():
    print(message.value.decode('utf-8'))
Drag options to blanks, or click blank then click option'
Aconsume
Bpoll
Csubscribe
Dpoll_messages
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'subscribe' instead of 'consume' to get messages.
Using a method that does not exist on the consumer object.
3fill in blank
hard

Fix the error in the code to produce a message with the correct key.

Kafka
producer.send('topic1', key=[1], value=b'Hello')
Drag options to blanks, or click blank then click option'
A'key1'
Bb'key1'
Ckey1
D123
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string without b prefix for the key.
Using a variable name without quotes or bytes.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps message keys to values.

Kafka
messages = {msg.[1]: msg.[2] for msg in consumer.consume()}
Drag options to blanks, or click blank then click option'
Akey
Bvalue
Ctopic
Dpartition
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'topic' or 'partition' instead of 'key' or 'value'.
Mixing up key and value positions.
5fill in blank
hard

Fill all three blanks to produce and flush a message to the topic with a key and value.

Kafka
producer.send('[1]', key=[2], value=[3])
producer.flush()
Drag options to blanks, or click blank then click option'
Atopic1
Bb'key123'
Cb'Hello Kafka!'
Db'value'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of bytes for key or value.
Forgetting to flush after sending.