Kafka behavior with acks=0 and synchronous producer

Viewed 233

What is the behavior of a synchronous producer when we set acks=0

producer.send(record).get();

The above statement will return immediately or we will wait for the response (RecordMetadata) ?

In other words, is it correct to say that with acks=0 and send().get() we will still wait for acknowledgment/response from the server ?

Is there some explanations in the apache Kafka documentation ?

1 Answers

The send() method is asynchronous. When called it adds the record to a buffer of pending record sends and immediately returns. This allows the producer to batch together individual records for efficiency.

acks=0 If set to zero then the producer will not wait for any acknowledgment from the server at all. The record will be immediately added to the socket buffer and considered sent. No guarantee can be made that the server has received the record in this case, and the retries configuration will not take effect (as the client won't generally know of any failures). The offset given back for each record will always be set to -1.

Send() returns java.util.concurrent.Future

get() Waits if necessary for the computation to complete, and then retrieves its result.

So for your question, get() won't be ignored , but it just won't need to wait for anything to complete because the send() will return prompt immediately without waiting for acknowledgment from the brokers,

So your statement is false

As said send() is async function that returns future, future have function called get() so it will wait for answer , you can read the code: Sender and KafkaProducer in github project, if ack=0 it just return an answer back without waiting for acknowledgment from the brokers

https://github.com/apache/kafka/blob/98bd590718658f3af2d7f1ff307d1d170624f199/clients/src/main/java/org/apache/kafka/clients/producer/internals/Sender.java#L579

Related