runable
This commit is contained in:
@@ -33,7 +33,8 @@ func NewProducer(brokers []string, topicIngest, topicDLQ, topicRetry string, log
|
||||
kgo.ProducerLinger(5_000_000), // 5ms linger -> batch small bursts
|
||||
kgo.ProducerBatchCompression(kgo.ZstdCompression()),
|
||||
kgo.MaxBufferedRecords(100_000),
|
||||
kgo.RequiredAcks(kgo.LeaderAck()),
|
||||
// franz-go enables idempotent writes by default, which requires acks=all.
|
||||
kgo.RequiredAcks(kgo.AllISRAcks()),
|
||||
kgo.ClientID("cdp-ingest"),
|
||||
)
|
||||
if err != nil {
|
||||
@@ -57,6 +58,12 @@ func (p *Producer) Close() {
|
||||
}
|
||||
|
||||
// Produce sends an event to the happy-path topic. Fire-and-forget.
|
||||
//
|
||||
// We detach the request's cancellation from the produce call: the HTTP
|
||||
// handler returns 200 as soon as the record is buffered, after which the
|
||||
// request context is cancelled. franz-go honours that cancellation and
|
||||
// drops the buffered record. context.WithoutCancel preserves values for
|
||||
// tracing but removes the deadline / Done signal.
|
||||
func (p *Producer) Produce(ctx context.Context, ev *model.IngestedEvent) error {
|
||||
payload, err := json.Marshal(ev)
|
||||
if err != nil {
|
||||
@@ -72,7 +79,7 @@ func (p *Producer) Produce(ctx context.Context, ev *model.IngestedEvent) error {
|
||||
{Key: "type", Value: []byte(ev.Type)},
|
||||
},
|
||||
}
|
||||
p.client.Produce(ctx, rec, func(r *kgo.Record, err error) {
|
||||
p.client.Produce(context.WithoutCancel(ctx), rec, func(r *kgo.Record, err error) {
|
||||
if err != nil {
|
||||
p.log.Error("kafka produce failed",
|
||||
zap.String("topic", r.Topic),
|
||||
|
||||
Reference in New Issue
Block a user