0
0
Kafkadevops~10 mins

Why consumer groups enable parallel processing 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 assign a consumer to a group.

Kafka
consumer = KafkaConsumer('my_topic', group_id=[1])
Drag options to blanks, or click blank then click option'
A'partition1'
B'topic1'
C'offset1'
D'group1'
Attempts:
3 left
💡 Hint
Common Mistakes
Using topic name instead of group ID
Using partition or offset as group ID
2fill in blank
medium

Complete the code to start consuming messages in parallel.

Kafka
for message in consumer.[1]():
    print(message.value)
Drag options to blanks, or click blank then click option'
Aconsume
Bpoll
Csubscribe
Dassign
Attempts:
3 left
💡 Hint
Common Mistakes
Using subscribe() which only sets topics
Using consume() which is not a KafkaConsumer method
3fill in blank
hard

Fix the error in the code to enable parallel processing with consumer groups.

Kafka
consumer = KafkaConsumer('my_topic', group_id=[1])
consumer.subscribe(['my_topic'])
Drag options to blanks, or click blank then click option'
ANone
B'my_topic'
C'my_group'
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving group_id as None disables consumer groups
Using empty string disables group behavior
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps partitions to consumers in a group.

Kafka
partition_map = {partition: consumer[1] for partition in partitions if partition [2] 0}
Drag options to blanks, or click blank then click option'
A.assign()
B>
C==
D.subscribe()
Attempts:
3 left
💡 Hint
Common Mistakes
Using subscribe() instead of assign()
Using == instead of > in condition
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that filters messages by offset and assigns them to a consumer group.

Kafka
filtered_messages = {msg[1]: msg.value for msg in messages if msg.offset [2] [3]
Drag options to blanks, or click blank then click option'
A.key
B>
C100
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using offset as key instead of message key
Using == instead of > for filtering
Using wrong offset value