0
0
Kafkadevops~10 mins

Why cloud-native deployment matters 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['localhost:9092']
B9092
C'kafka://localhost'
D'localhost:9092'
Attempts:
3 left
💡 Hint
Common Mistakes
Using only port number without host
Using a list instead of a string
Using an incorrect URL format
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'
Ab'my_topic'
B123
C'my_topic'
Dtopic_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using an integer instead of a string
Using bytes instead of string
Using an undefined variable
3fill in blank
hard

Fix the error in the Kafka consumer code to subscribe to a topic.

Kafka
consumer = KafkaConsumer()
consumer.subscribe([1])
Drag options to blanks, or click blank then click option'
Amy_topic
B['my_topic']
C'my_topic'
Db'my_topic'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string instead of a list
Passing bytes instead of string
Using an undefined variable
4fill in blank
hard

Fill both blanks to create a cloud-native Kafka consumer that reads from a topic and auto-commits offsets.

Kafka
consumer = KafkaConsumer([1], bootstrap_servers='localhost:9092', [2]=True)
Drag options to blanks, or click blank then click option'
A'my_topic'
Bauto_commit
Cenable_auto_commit
Dgroup_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter name for auto commit
Passing topic name as bytes
Missing quotes around topic name
5fill in blank
hard

Fill all three blanks to produce a cloud-native Kafka producer that sends JSON messages with a key and flushes the buffer.

Kafka
import json
producer = KafkaProducer(bootstrap_servers='localhost:9092', value_serializer=lambda v: json.dumps(v).encode('utf-8'))
producer.send([1], key=[2], value={'event': 'start'})
producer.[3]()
Drag options to blanks, or click blank then click option'
A'events'
Bb'key1'
Cflush
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of bytes for key
Not flushing the producer
Using wrong method to send messages