0
0
Kafkadevops~10 mins

Consumer offset commit strategies 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 enable automatic offset commits in a Kafka consumer.

Kafka
props.put("enable.auto.commit", [1]);
Drag options to blanks, or click blank then click option'
A"auto"
B"commit"
C"false"
D"true"
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean true instead of string "true"
Setting the property to "false" disables auto commit
2fill in blank
medium

Complete the code to commit offsets synchronously after processing records.

Kafka
consumer.[1]();
Drag options to blanks, or click blank then click option'
AcommitSync
BcommitAsync
CcommitOffsets
DcommitNow
Attempts:
3 left
💡 Hint
Common Mistakes
Using commitAsync() when synchronous commit is required
Calling a non-existent method commitOffsets()
3fill in blank
hard

Fix the error in the code to commit offsets asynchronously with a callback.

Kafka
consumer.[1](new OffsetCommitCallback() {
    public void onComplete(Map<TopicPartition, OffsetAndMetadata> offsets, Exception e) {
        if (e != null) {
            System.err.println("Commit failed");
        }
    }
});
Drag options to blanks, or click blank then click option'
AcommitOffsets
BcommitSync
CcommitAsync
DcommitNow
Attempts:
3 left
💡 Hint
Common Mistakes
Using commitSync() with a callback parameter
Calling a non-existent method commitOffsets()
4fill in blank
hard

Fill both blanks to create a manual offset commit after processing each record.

Kafka
for (ConsumerRecord<String, String> record : records) {
    process(record);
    consumer.[1](Collections.singletonMap(
        new TopicPartition(record.topic(), record.partition()),
        new OffsetAndMetadata(record.offset() + [2])
    ));
}
Drag options to blanks, or click blank then click option'
AcommitSync
BcommitAsync
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using commitAsync() without handling failures
Not incrementing the offset by 1
5fill in blank
hard

Fill all three blanks to configure a Kafka consumer for manual offset commits with a 5-second commit interval.

Kafka
props.put("enable.auto.commit", [1]);
props.put("auto.commit.interval.ms", [2]);
consumer.[3]();
Drag options to blanks, or click blank then click option'
A"false"
B"5000"
CcommitSync
DcommitAsync
Attempts:
3 left
💡 Hint
Common Mistakes
Setting enable.auto.commit to "true" disables manual commits
Using commitSync() when asynchronous commit is intended