0
0
Kafkadevops~10 mins

At-least-once delivery 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 commit the offset after processing the message.

Kafka
consumer.commitSync([1]);
Drag options to blanks, or click blank then click option'
Anull
Btrue
Cfalse
Doffsets
Attempts:
3 left
💡 Hint
Common Mistakes
Passing true or false instead of offsets causes errors.
Not committing offsets can lead to message reprocessing.
2fill in blank
medium

Complete the code to enable auto-commit for at-least-once delivery.

Kafka
"enable.auto.commit": [1],
Drag options to blanks, or click blank then click option'
A"false"
BTrue
CFalse
D"true"
Attempts:
3 left
💡 Hint
Common Mistakes
Using string 'true' instead of boolean true causes config issues.
Setting auto-commit to false disables automatic commits.
3fill in blank
hard

Fix the error in the code to process messages and commit offsets synchronously.

Kafka
while (true) {
    ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
    for (ConsumerRecord<String, String> record : records) {
        process(record);
    }
    consumer.[1]();
}
Drag options to blanks, or click blank then click option'
AcommitOffset
BcommitAsync
CcommitSync
Dcommit
Attempts:
3 left
💡 Hint
Common Mistakes
Using commitAsync() can cause message duplication.
commit() and commitOffset() are not valid Kafka consumer methods.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that stores offsets for partitions with offset greater than 5.

Kafka
Map<TopicPartition, OffsetAndMetadata> offsets = records.partitions().stream()
    .collect(Collectors.toMap(
        partition -> partition,
        partition -> new OffsetAndMetadata([1])
    ));

if (offsets.entrySet().stream().anyMatch(entry -> entry.getValue().offset() [2] 5)) {
    consumer.commitSync(offsets);
}
Drag options to blanks, or click blank then click option'
Arecords.records(partition).get(records.records(partition).size() - 1).offset() + 1
Brecords.records(partition).get(0).offset()
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using the first record's offset instead of the last.
Using '<' instead of '>' in the condition.
5fill in blank
hard

Fill all three blanks to create a Python dictionary comprehension that stores offsets for words longer than 3 characters.

Kafka
offsets = {word[1]: [2] for word in words if len(word) [3] 3}
Drag options to blanks, or click blank then click option'
A.upper()
Blen(word)
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' instead of '>' in the condition.
Using the word itself instead of its uppercase form as key.