Complete the code to catch exceptions when sending a message.
try { producer.send(record).get(); } catch ([1] e) { e.printStackTrace(); }
The ExecutionException is thrown when the send operation fails asynchronously.
Complete the code to handle interrupted exceptions during send.
try { producer.send(record).get(); } catch (ExecutionException e) { e.printStackTrace(); } catch ([1] e) { Thread.currentThread().interrupt(); }
The InterruptedException must be caught to handle thread interruption properly.
Fix the error in the catch block to handle Kafka exceptions correctly.
try { producer.send(record).get(); } catch ([1] e) { System.err.println("Kafka error: " + e.getMessage()); }
The ExecutionException wraps Kafka client errors thrown during the send operation.
Fill both blanks to create a retry loop that handles send failures.
int retries = 0; boolean sent = false; while (!sent && retries < 3) { try { producer.send(record).get(); sent = true; } catch ([1] e) { retries++; System.out.println("Retry " + retries); Thread.sleep([2]); } }
Use ExecutionException to catch send failures and 500 milliseconds as sleep time between retries.
Fill all three blanks to log error details and rethrow the exception.
try { producer.send(record).get(); } catch ([1] e) { logger.error("Send failed: {}", [2]); throw new [3](e); }
Catch ExecutionException, log the error message with e.getMessage(), and rethrow as a RuntimeException.