fix(go): require kafka write acknowledgements
This commit is contained in:
@@ -41,6 +41,8 @@ func NewKafkaSink(cfg KafkaConfig) (*KafkaSink, error) {
|
||||
Addr: kafka.TCP(cfg.Brokers...),
|
||||
Balancer: &kafka.Hash{},
|
||||
AllowAutoTopicCreation: false,
|
||||
RequiredAcks: kafka.RequireAll,
|
||||
Async: false,
|
||||
}, cfg), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package eventbus
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/segmentio/kafka-go"
|
||||
@@ -63,6 +64,31 @@ func TestKafkaSinkRejectsUnknownProtocol(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewKafkaSinkUsesProductionDeliveryGuarantees(t *testing.T) {
|
||||
sink, err := NewKafkaSink(KafkaConfig{Brokers: []string{"127.0.0.1:9092"}})
|
||||
if err != nil {
|
||||
t.Fatalf("NewKafkaSink() error = %v", err)
|
||||
}
|
||||
defer sink.Close()
|
||||
|
||||
writer, ok := sink.writer.(*kafka.Writer)
|
||||
if !ok {
|
||||
t.Fatalf("writer type = %s", reflect.TypeOf(sink.writer))
|
||||
}
|
||||
if writer.RequiredAcks != kafka.RequireAll {
|
||||
t.Fatalf("RequiredAcks = %v, want %v", writer.RequiredAcks, kafka.RequireAll)
|
||||
}
|
||||
if writer.Async {
|
||||
t.Fatal("writer must publish synchronously so Kafka errors propagate")
|
||||
}
|
||||
if writer.AllowAutoTopicCreation {
|
||||
t.Fatal("writer must not auto-create production topics")
|
||||
}
|
||||
if _, ok := writer.Balancer.(*kafka.Hash); !ok {
|
||||
t.Fatalf("balancer type = %s, want *kafka.Hash", reflect.TypeOf(writer.Balancer))
|
||||
}
|
||||
}
|
||||
|
||||
type recordingWriter struct {
|
||||
messages []kafka.Message
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user