The provided code snippet outlines a Java program that demonstrates how to properly configure and use the Kafka producer API for sending messages, especially in scenarios where broker failover or rolling upgrades might occur. The original problematic configuration is contrasted with corrected settings to ensure message delivery reliability.
Problematic Configuration (Original Code)
- Retries: Set to 20, which may not be sufficient during a broker failover window.
- Retry Backoff: Set to 100ms, too short for the Kafka brokers' startup time in newer versions.
- Delivery Timeout: Not explicitly set, leading to potential message loss if delivery is delayed beyond the default timeout.
- Request Timeout: Default or insufficient value (not specified), which might cause issues with slow broker responses.
Corrected Configuration
- Retries: Set to
Integer.MAX_VALUEfor maximum retries during failover windows. - Retry Backoff: Increased to 500ms, matching the startup time of Kafka brokers in version 3.8 and later.
- Delivery Timeout: Set to 2 minutes (120 seconds) to cover rolling upgrade scenarios where broker availability might be temporarily compromised.
- Request Timeout: Increased
Read the full article at DEV Community
Want to create content about this topic? Use Nemati AI tools to generate articles, social posts, and more.

![[AINews] The Unreasonable Effectiveness of Closing the Loop](/_next/image?url=https%3A%2F%2Fmedia.nemati.ai%2Fmedia%2Fblog%2Fimages%2Farticles%2F600e22851bc7453b.webp&w=3840&q=75)



