Complete the code to enable auto-commit in Kafka consumer configuration.
props.put("enable.auto.commit", [1]);
Setting enable.auto.commit to true enables Kafka consumer to commit offsets automatically.
Complete the code to manually commit offsets synchronously in Kafka consumer.
consumer.[1]();commitSync() commits offsets synchronously, blocking until the commit is acknowledged.
Fix the error in the code to disable auto-commit in Kafka consumer configuration.
props.put("enable.auto.commit", [1]);
The value must be a string "false" to properly disable auto-commit in Kafka consumer properties.
Fill both blanks to create a dictionary comprehension that maps topic partitions to their latest committed offsets.
offsets = {tp: consumer.[1](tp) for tp in consumer.[2]() if tp is not None}consumer.committed(tp) gets the committed offset for a topic partition, and consumer.assignment() returns the set of partitions assigned to the consumer.
Fill all three blanks to commit offsets asynchronously with a callback that prints success or error.
consumer.[1](offsets, new OffsetCommitCallback() { public void onComplete(Map<TopicPartition, OffsetAndMetadata> offsets, Exception e) { if (e == null) { System.out.println("Commit successful for [2]"); } else { System.err.println("Commit failed: " + [3]); } } });
commitAsync commits offsets asynchronously. The callback receives the offsets and an exception e. If e is null, commit succeeded; otherwise, print the error message with e.getMessage().