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...),
|
Addr: kafka.TCP(cfg.Brokers...),
|
||||||
Balancer: &kafka.Hash{},
|
Balancer: &kafka.Hash{},
|
||||||
AllowAutoTopicCreation: false,
|
AllowAutoTopicCreation: false,
|
||||||
|
RequiredAcks: kafka.RequireAll,
|
||||||
|
Async: false,
|
||||||
}, cfg), nil
|
}, cfg), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package eventbus
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/segmentio/kafka-go"
|
"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 {
|
type recordingWriter struct {
|
||||||
messages []kafka.Message
|
messages []kafka.Message
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user