Complete the code to set the consumer group ID in Kafka consumer configuration.
props.put("group.id", [1]);
The group.id property sets the consumer group identifier, which is essential for Kafka to manage consumer groups.
Complete the code to subscribe the consumer to a topic named "orders".
consumer.subscribe(Collections.[1]("orders"));
emptyList which subscribes to no topics.listOf which is not a Java Collections method.The singletonList method creates an immutable list with a single element, which is used to subscribe to one topic.
Fix the error in the code to poll messages from Kafka consumer with a timeout of 100 milliseconds.
ConsumerRecords<String, String> records = consumer.poll(Duration.[1](100));
ofSeconds which would mean 100 seconds.ofMinutes which is too long.The poll method requires a Duration object specifying the timeout. ofMillis creates a duration in milliseconds.
Fill both blanks to create a map of topic partitions to offsets for committing offsets manually.
Map<TopicPartition, OffsetAndMetadata> offsets = Map.of(new TopicPartition("orders", [1]), new OffsetAndMetadata([2]));
The first blank is the partition number (0), and the second blank is the offset to commit (15).
Fill all three blanks to create a consumer configuration with bootstrap servers, group ID, and auto offset reset policy.
props.put("bootstrap.servers", [1]); props.put("group.id", [2]); props.put("auto.offset.reset", [3]);
The bootstrap servers specify the Kafka cluster address, the group ID identifies the consumer group, and the auto offset reset policy defines where to start if no offset is found.