Maybe I am getting the meaning/aim of idempotency in this library or Kafka in general. However, what I understand from the docs, code comments and other blog posts is that, enabling it (like show below) is meant to produce same message exactly once. Correct me if I am wrong please.
Technically, I am trying to produce same message exactly once.
Thanks
Note: I have seen this and this examples but they seem very complicated rather than keeping the producer and consumer in different files. To be honest, I am not even sure if they are applicable to me.
Versions
Sarama
Kafka
Go
v1.43.2
v3.3.2
1.22
Configuration
package main
import (
"log"
"time"
"github.com/IBM/sarama"
)
func main() {
cfg := sarama.NewConfig()
cfg.ClientID = "test"
cfg.Version = sarama.V3_3_2_0
cfg.Producer.Return.Successes = true
cfg.Producer.Retry.Max = 30
cfg.Producer.Retry.Backoff = time.Millisecond * 10
// Enable EOS (Exactly Once Semantic)
cfg.Producer.Idempotent = true
cfg.Producer.RequiredAcks = sarama.WaitForAll
cfg.Net.MaxOpenRequests = 1
//
pro, err := sarama.NewSyncProducer([]string{":9093"}, cfg)
if err != nil {
log.Fatalln(err)
}
msg := sarama.ProducerMessage{
Topic: "warnings-topic", // This topic has only one partition
Value: sarama.StringEncoder("body"),
Timestamp: time.Now(),
}
// Purposely simulating duplicate messages
for i := 1; i <= 2; i++ {
prt, off, err := pro.SendMessage(&msg)
if err != nil {
log.Fatalln(err)
}
log.Printf("I: %d PARTITION: %d OFFSET: %d\n", i, prt, off)
}
}
$ go run -race main.go
2024/05/19 19:22:21 I: 1PARTITION: 0 OFFSET: 39841
2024/05/19 19:22:21 I: 2PARTITION: 0 OFFSET: 39842
Description
Hi,
Maybe I am getting the meaning/aim of idempotency in this library or Kafka in general. However, what I understand from the docs, code comments and other blog posts is that, enabling it (like show below) is meant to produce same message exactly once. Correct me if I am wrong please.
Technically, I am trying to produce same message exactly once.
Thanks
Note: I have seen this and this examples but they seem very complicated rather than keeping the producer and consumer in different files. To be honest, I am not even sure if they are applicable to me.
Versions
Configuration
Additional Context