I am using KafkaProducer.send() method to publish records to Kafka. This is an asynchronous method. My application is publishing about 20k records to Kafka. A lot of times after successfully sending about 10k records I get Timeout Exception. I increased batch.size and linger.ms which reduced the problem but i still get Timeout Exception sometimes. Is there a way to send only 10k records at a time wait for them to complete and then send the next batch?? I do not want to make it synchronous by using send.get() because that will make it very slow. This is the exception I am getting.
Error publishing object on partition 0 org.apache.kafka.common.errors.TimeoutException: Expiring 1 record(s)
flush()
after each record? – Deadpool