Producers
- It writes data to topics
- It automatically knows to which broker and partition to write to
- Producer can choose to receive acknowledgement
- controlled by
acks config
// topic and value are mandatory
sendData(String topic, int partition, K key, V value, Map headers)
Producer Configs
retries
- Number of times to retry a request that fails with a transient error
retry.backoff.ms
- Time to wait before attempting to retry
client.id
enable.idempotence: true/false
- ensures exactly one message in broker
- requirements
max.in.flight.requests.per.connection <= 5
retries > 0
acks = all
transactional.id
- If given, implies
enable.idempotence
- By default, Tx requires a cluster of at least three brokers
compression.type
Delivery Semantics for Producers
- Producer choose when to retry if failure happens
- 3 delivery semantics:
At least once
- with
acks=all, retries until successfully publishes to topic with no data loss
- can cause duplicate messages
At most once
- does not retry if failure happens
- no duplicate messages
Exactly once
- most difficult to achieve
- message is delivered exactly once
- messaging system and client must cooperate to achieve this
