A Kafka producer’s acknowledgment strategy decides when a publish request counts as acknowledged. Choose it according to the cost of losing a message versus the latency of waiting for confirmation. Set it with the producer property `acks`. section 5.1.1
The three settings differ in what the producer learns:
- `acks=all` (also `acks=-1`): the partition leader acknowledges only after all in-sync replicas have received the message. This is the usual choice when the data is important. section 5.1.1 section 8.1.3
- `acks=1`: the leader acknowledges when it receives the message. The response is faster, but a leader failure before replication can lose the message. section 5.1.1
- `acks=0`: the producer does not wait for a broker acknowledgment. It offers higher performance but no confirmation that the message arrived or was persisted; use it only when loss is tolerable. section 5.1.1
Configure a producer
To publish price changes while waiting for replication, run `kafka-console-producer.sh --topic products.prices.changelog --bootstrap-server localhost:9092 --producer-property acks=all`. Change the final value to `1` or `0` to try the other strategies. section 5.1.1
`acks=all` also interacts with the topic’s `min.insync.replicas` setting. If too few replicas are in sync, the producer receives an error and retries rather than getting an acknowledgment. A producer waiting for an ACK also retries after a response timeout or broker error; if delivery continues to fail until `delivery.timeout.ms`, it raises an exception for the application to handle. Do not blindly resend after that exception. section 5.1.2 section 8.1.3
$ kafka-console-producer.sh \
--topic products.prices.changelog.min-isr-2 \
--bootstrap-server localhost:9092 \
--producer-property acks=all
>cola all
>[…] WARN [Producer clientId=console-producer] Got error produce response
with correlation id 10 on topic-partition
products.prices.changelog.min-isr-2-2, retrying (2 attempts left).
Error: NOT_ENOUGH_REPLICAS
(org.apache.kafka.clients.producer.internals.Sender)
[…] WARN [Producer clientId=console-producer] Got error produce response
with correlation id 11 on topic-partition
products.prices.changelog.min-isr-2-2, retrying (1 attempts left).
Error: NOT_ENOUGH_REPLICAS
(org.apache.kafka.clients.producer.internals.Sender)
[…] WARN [Producer clientId=console-producer] Got error produce response
with correlation id 12 on topic-partition
products.prices.changelog.min-isr-2-2, retrying (0 attempts left).
Error: NOT_ENOUGH_REPLICAS
(org.apache.kafka.clients.producer.internals.Sender)
[…] ERROR Error when sending message to topic
products.prices.changelog.min-isr-2 with key: null, value: 8 bytes with
error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.NotEnoughReplicasException: Messages are
rejected since there are fewer in-sync replicas than required.
See the `acks=all` producer report `NOT_ENOUGH_REPLICAS` and retry when a topic requiring two in-sync replicas has only one. section 5.1.2

