0
0
Kafkadevops~10 mins

Offset management 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 current offset synchronously.

Kafka
consumer.commitSync([1]);
Drag options to blanks, or click blank then click option'
Aoffsets
Btrue
Cnull
Dfalse
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.
2fill in blank
medium

Complete 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'
A5
B-1
C'5'
DlatestOffset
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.
3fill in blank
hard

Fix 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'
Anull
Bundefined
C{}
Doffsets
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.
4fill in blank
hard

Fill 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'
ATopicPartition
BPartition
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Partition' instead of 'TopicPartition' causes errors.
Using partition 1 commits offset to the wrong partition.
5fill in blank
hard

Fill 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'
ATopicPartition
Borders
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using partition 3 commits to the wrong partition.
Using wrong topic name causes commit to fail.