Complete the code to produce messages to a specific partition in Kafka.
producer.send(new ProducerRecord<>("topic", [1], "key", "value"));
Partition number must be an integer like 0 to send messages to a specific partition.
Complete the code to ensure message ordering within a partition by setting the correct key.
producer.send(new ProducerRecord<>("topic", [1], "value"));
Using a consistent key like "userID" ensures messages with the same key go to the same partition, preserving order.
Fix the error in the code to consume messages in order from a single partition.
consumer.assign(Collections.singleton(new TopicPartition("topic", [1])));
The partition number must be an integer like 0, not a string or null.
Fill both blanks to create a dictionary comprehension that maps partitions to their last committed offsets.
offsets = {tp.partition(): [1] for tp in consumer.assignment() if tp.partition() [2] 0}We get the committed offset for each partition and filter partitions with number greater than 0.
Fill all three blanks to create a dictionary comprehension that maps partition numbers to their latest offsets if offset is greater than 100.
latest_offsets = { [1]: [2] for tp in consumer.assignment() if [3] > 100}We map partition numbers to their current positions (latest offsets) and filter those with offsets greater than 100.