Complete the code to specify the number of partitions when creating a Kafka topic.
new NewTopic("my-topic", [1], (short) 1);
The number of partitions must be a positive integer. Here, 3 partitions are specified.
Complete the code to send a message to a specific partition in Kafka.
producer.send(new ProducerRecord<>("my-topic", [1], "key", "value"));
The partition number must be an integer. Here, the message is sent to partition 1.
Fix the error in the code to correctly create a Kafka topic with partitions.
NewTopic topic = new NewTopic("my-topic", [1], (short) 1);
The number of partitions must be a positive integer without quotes. Using 3 is correct.
Fill both blanks to create a ProducerRecord that sends a message to partition 2 with key "user1".
ProducerRecord<String, String> record = new ProducerRecord<>("my-topic", [1], [2], "message");
The first blank is the partition number 2 (integer), the second blank is the key "user1" (string).
Fill all three blanks to create a NewTopic with name "events", 4 partitions, and replication factor 2.
NewTopic topic = new NewTopic([1], [2], (short) [3]);
The topic name is "events" (string), partitions is 4 (integer), replication factor is 2 (short integer).