0
0
Kafkadevops~10 mins

Why advanced patterns handle complex flows 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 produce 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'
Btopic='my_topic'
Cb'my_topic'
Dmy_topic
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the topic name as bytes instead of string.
Using keyword arguments instead of positional argument.
2fill in blank
medium

Complete the code to consume messages from a Kafka topic.

Kafka
consumer = KafkaConsumer([1], bootstrap_servers='localhost:9092')
Drag options to blanks, or click blank then click option'
A['my_topic']
B'my_topic'
Cb'my_topic'
Dtopic='my_topic'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string instead of a list.
Passing bytes instead of string.
3fill in blank
hard

Fix the error in the code to commit offsets manually after processing messages.

Kafka
for message in consumer:
    process(message)
    consumer.[1]()
Drag options to blanks, or click blank then click option'
Acommit_async
Bcommit
Ccommit_sync
Dcommit_offsets
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like commit_sync or commit_offsets.
Using commit_async() which commits asynchronously.
4fill in blank
hard

Fill both blanks to create a Kafka Streams topology that filters messages with value length greater than 5.

Kafka
builder = StreamsBuilder()
stream = builder.stream([1])
filtered = stream.filter(lambda k, v: len(v) [2] 5)
Drag options to blanks, or click blank then click option'
A'input-topic'
B>
C<
D'output-topic'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the output topic as input.
Using the less than operator instead of greater than.
5fill in blank
hard

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

Kafka
result = { [1]: [2] for [3] in data.items() if [2] > 0 }
Drag options to blanks, or click blank then click option'
Ak
Bv
Ck, v
D{k}
Attempts:
3 left
💡 Hint
Common Mistakes
Using only keys or only values in the comprehension.
Incorrect unpacking of items.