0
0
Kafkadevops~10 mins

Partitioner behavior 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 specify the partition key for a Kafka message.

Kafka
producer.send(topic, key=[1], value="message")
Drag options to blanks, or click blank then click option'
A"user123"
B123
CNone
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using an integer as key without serialization
Passing None as key when a key is expected
2fill in blank
medium

Complete the code to create a custom partitioner class in Kafka.

Kafka
class CustomPartitioner:
    def partition(self, key, partitions, [1]):
        return hash(key) % len(partitions)
Drag options to blanks, or click blank then click option'
Aconfig
Bvalue
Ctopic
Dmetadata
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter names
Ignoring the metadata parameter
3fill in blank
hard

Fix the error in the partitioner code to correctly compute the partition index.

Kafka
def partition(key, partitions):
    index = hash(key) [1] len(partitions)
    return index
Drag options to blanks, or click blank then click option'
A+
B%
C-
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using division or subtraction instead of modulo
Returning a value outside partition range
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps partitions to message counts greater than 10.

Kafka
partition_counts = {p: counts[p] [1] p [2] counts if counts[p] > 10}
Drag options to blanks, or click blank then click option'
Afor
Bin
Cif
Delse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'if' or 'else' in place of 'for' or 'in'
Incorrect comprehension syntax
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values greater than 5.

Kafka
filtered = [1]: [2] for [3] in data if data[[3]] > 5
Drag options to blanks, or click blank then click option'
Ak.upper()
Bdata[k]
Ck
Dv
Attempts:
3 left
💡 Hint
Common Mistakes
Using values instead of keys in iteration
Not transforming keys to uppercase
Incorrect comprehension syntax