Complete the code to enable idempotence for the Kafka producer.
Properties props = new Properties(); props.put("bootstrap.servers", "localhost:9092"); props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); props.put("[1]", "true");
Setting enable.idempotence to true enables idempotent producer behavior in Kafka.
Complete the code to set the number of retries for the Kafka producer.
Properties props = new Properties(); props.put("bootstrap.servers", "localhost:9092"); props.put("retries", "[1]");
The retries property expects a string representing a number. Setting it to "3" means the producer will retry sending messages up to 3 times.
Fix the error in the code to ensure safe retries with idempotency.
props.put("max.in.flight.requests.per.connection", "[1]");
Setting max.in.flight.requests.per.connection to "1" ensures that only one request is sent at a time, preventing message reordering during retries when idempotence is enabled.
Fill both blanks to configure the producer for idempotent retries with proper acknowledgments.
props.put("[1]", "all"); props.put("[2]", "true");
Setting acks to "all" ensures the leader and all replicas acknowledge the message. Enabling enable.idempotence to "true" ensures safe retries without duplicates.
Fill all three blanks to create a Kafka producer configuration that safely retries with idempotency and limits in-flight requests.
props.put("[1]", "true"); props.put("[2]", "3"); props.put("[3]", "1");
This configuration enables idempotency, sets retries to 3, and limits in-flight requests to 1 to prevent message reordering during retries.