Sobes.tech
Senior

Have you configured Kafka Producer? What settings do you know?

sobes.tech AI

Answer from AI

When configuring Kafka Producer in Java, the following key parameters are usually set:

  • bootstrap.servers — addresses of Kafka brokers for connection.
  • key.serializer and value.serializer — classes for serializing message keys and values.
  • acks — level of write confirmation (e.g., all for maximum reliability).
  • retries — number of retry attempts on errors.
  • batch.size — size of message batches for performance optimization.
  • linger.ms — delay before sending a batch to gather more messages.
  • buffer.memory — amount of memory allocated for the message buffer.
  • compression.type — message compression type (none, gzip, snappy, lz4, zstd).

Example configuration:

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("acks", "all");
props.put("retries", 3);
props.put("batch.size", 16384);
props.put("linger.ms", 1);
props.put("buffer.memory", 33554432);

KafkaProducer<String, String> producer = new KafkaProducer<>(props);

These settings allow balancing between reliability, performance, and latency when sending messages.