Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without quotes instead of string topic names.
Using invalid topic name formats.
✗ Incorrect
Kafka topic names are strings and usually enclosed in quotes. Here, "events-topic" is the correct string format.
2fill in blank
mediumComplete the code to consume events from a Kafka topic.
Kafka
consumer.subscribe([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string directly instead of a list of strings.
Using variable names without quotes.
✗ Incorrect
Kafka consumer.subscribe expects a list of topic names, so the topic name must be inside a list like ["events-topic"].
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using encode instead of decode.
Trying to parse bytes directly without decoding.
✗ Incorrect
Kafka message values are bytes and need to be decoded to strings using decode('utf-8').
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'in' instead of __contains__ for key check.
Using != instead of == for filtering.
✗ Incorrect
First, check if 'type' key exists using __contains__, then check if its value equals 'UserCreated'.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>' for version filtering.
Swapping key and value in dictionary comprehension.
✗ Incorrect
Use event['id'] as key, event['payload'] as value, and filter events where version is greater than 1.