Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to commit the current offset synchronously.
Kafka
consumer.commitSync([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing true or false causes errors because commitSync expects an offset map or null.
Passing 'offsets' without defining it causes runtime errors.
✗ Incorrect
Passing null to commitSync commits the latest offsets for the consumer's assigned partitions.
2fill in blank
mediumComplete the code to seek to a specific offset for a partition.
Kafka
consumer.seek(new TopicPartition('my-topic', 0), [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like '5' instead of number 5 causes type errors.
Using -1 is invalid for seek and causes runtime errors.
✗ Incorrect
The seek method requires a numeric offset to move the consumer to that position.
3fill in blank
hardFix the error in committing offsets asynchronously with a callback.
Kafka
consumer.commitAsync([1], (err, data) => { if (err) console.error('Commit failed', err); else console.log('Commit succeeded', data); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing undefined causes the commitAsync to fail silently.
Passing an empty object {} commits nothing and may cause unexpected behavior.
✗ Incorrect
Passing null commits the latest offsets; passing undefined or empty object causes errors.
4fill in blank
hardFill both blanks to create a map for committing offset 10 for partition 0 of 'my-topic'.
Kafka
const offsets = new Map(); offsets.set(new [1]('my-topic', [2]), { offset: 10 });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Partition' instead of 'TopicPartition' causes errors.
Using partition 1 commits offset to the wrong partition.
✗ Incorrect
TopicPartition is the class representing topic and partition; partition number is 0 here.
5fill in blank
hardFill all three blanks to commit offset 15 for partition 2 of 'orders' topic asynchronously.
Kafka
const offsets = new Map(); offsets.set(new [1]('[2]', [3]), { offset: 15 }); consumer.commitAsync(offsets, (err) => { if (err) console.error('Commit error', err); else console.log('Commit successful'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using partition 3 commits to the wrong partition.
Using wrong topic name causes commit to fail.
✗ Incorrect
TopicPartition class with topic 'orders' and partition 2 is used to commit offset 15 asynchronously.