0
0
Kafkadevops~10 mins

Event sourcing pattern 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 an event to Kafka topic.

Kafka
producer.send([1], value=event_data)
Drag options to blanks, or click blank then click option'
Aevents_topic
B"events-topic"
Cevents-topic
DeventsTopic
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without quotes instead of string topic names.
Using invalid topic name formats.
2fill in blank
medium

Complete the code to consume events from a Kafka topic.

Kafka
consumer.subscribe([1])
Drag options to blanks, or click blank then click option'
A"events-topic"
Bevents_topic
Cevents-topic
D["events-topic"]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string directly instead of a list of strings.
Using variable names without quotes.
3fill in blank
hard

Fix the error in the event processing loop to correctly decode event data.

Kafka
for message in consumer:
    event = message.value.[1]('utf-8')
Drag options to blanks, or click blank then click option'
AtoString
Bencode
Cdecode
Dparse
Attempts:
3 left
💡 Hint
Common Mistakes
Using encode instead of decode.
Trying to parse bytes directly without decoding.
4fill in blank
hard

Fill both blanks to filter and store only events with type 'UserCreated'.

Kafka
filtered_events = [event for event in events if event[1] 'type' and event['type'] [2] 'UserCreated']
Drag options to blanks, or click blank then click option'
A.__contains__
B==
C!=
Din
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'in' instead of __contains__ for key check.
Using != instead of == for filtering.
5fill in blank
hard

Fill all three blanks to create a dictionary of event IDs and their payloads for events with version > 1.

Kafka
event_dict = [1]: [2] for event in events if event['version'] [3] 1
Drag options to blanks, or click blank then click option'
Aevent['id']
Bevent['payload']
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>' for version filtering.
Swapping key and value in dictionary comprehension.