Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
ae4ae64694 | |||
2ca4e5c74e | |||
2809ebcaeb | |||
3f04403319 | |||
8edfc11eef | |||
cb5ef75e09 | |||
d5bd105cc6 | |||
1ba02ed8ad | |||
7c5da60556 | |||
849bbd7a09 | |||
f461bb6876 | |||
201d22d1c4 | |||
ff6a272594 | |||
1018abe7bd |
@ -3,3 +3,19 @@ run:
|
|||||||
deadline: 5m
|
deadline: 5m
|
||||||
issues-exit-code: 1
|
issues-exit-code: 1
|
||||||
tests: true
|
tests: true
|
||||||
|
|
||||||
|
linters:
|
||||||
|
enable:
|
||||||
|
- staticcheck
|
||||||
|
- unused
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- prealloc
|
||||||
|
- unconvert
|
||||||
|
- nakedret
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
govet:
|
||||||
|
check-all: true
|
||||||
|
enable:
|
||||||
|
- fieldalignment
|
27
carrier.go
27
carrier.go
@ -1,6 +1,10 @@
|
|||||||
package kgo
|
package kgo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/twmb/franz-go/pkg/kgo"
|
"github.com/twmb/franz-go/pkg/kgo"
|
||||||
"go.unistack.org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
@ -53,24 +57,37 @@ func (c RecordCarrier) Keys() []string {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func setHeaders(r *kgo.Record, md metadata.Metadata) {
|
func setHeaders(r *kgo.Record, md metadata.Metadata, exclude ...string) {
|
||||||
seen := make(map[string]struct{})
|
seen := make(map[string]struct{})
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
for k, v := range md {
|
for k, v := range md {
|
||||||
|
k = http.CanonicalHeaderKey(k)
|
||||||
|
|
||||||
|
if _, ok := seen[k]; ok {
|
||||||
|
continue loop
|
||||||
|
}
|
||||||
|
|
||||||
|
if slices.ContainsFunc(exclude, func(s string) bool {
|
||||||
|
return strings.EqualFold(s, k)
|
||||||
|
}) {
|
||||||
|
continue loop
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < len(r.Headers); i++ {
|
for i := 0; i < len(r.Headers); i++ {
|
||||||
if r.Headers[i].Key == k {
|
if strings.EqualFold(r.Headers[i].Key, k) {
|
||||||
// Key exist, update the value.
|
// Key exist, update the value.
|
||||||
r.Headers[i].Value = []byte(v)
|
r.Headers[i].Value = []byte(v)
|
||||||
continue loop
|
continue loop
|
||||||
} else if _, ok := seen[k]; ok {
|
|
||||||
continue loop
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Key does not exist, append new header.
|
// Key does not exist, append new header.
|
||||||
r.Headers = append(r.Headers, kgo.RecordHeader{
|
r.Headers = append(r.Headers, kgo.RecordHeader{
|
||||||
Key: k,
|
Key: k,
|
||||||
Value: []byte(v),
|
Value: []byte(v),
|
||||||
})
|
})
|
||||||
|
|
||||||
seen[k] = struct{}{}
|
seen[k] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
10
event.go
10
event.go
@ -8,11 +8,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type event struct {
|
type event struct {
|
||||||
ctx context.Context
|
|
||||||
topic string
|
|
||||||
err error
|
|
||||||
sync.RWMutex
|
|
||||||
msg *broker.Message
|
msg *broker.Message
|
||||||
|
err error
|
||||||
|
ctx context.Context
|
||||||
|
|
||||||
|
topic string
|
||||||
|
|
||||||
|
sync.RWMutex
|
||||||
ack bool
|
ack bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
go.mod
15
go.mod
@ -1,8 +1,6 @@
|
|||||||
module go.unistack.org/micro-broker-kgo/v3
|
module go.unistack.org/micro-broker-kgo/v3
|
||||||
|
|
||||||
go 1.22.7
|
go 1.22.0
|
||||||
|
|
||||||
toolchain go1.23.3
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
@ -10,19 +8,20 @@ require (
|
|||||||
github.com/twmb/franz-go/pkg/kadm v1.14.0
|
github.com/twmb/franz-go/pkg/kadm v1.14.0
|
||||||
github.com/twmb/franz-go/pkg/kmsg v1.9.0
|
github.com/twmb/franz-go/pkg/kmsg v1.9.0
|
||||||
go.opentelemetry.io/otel v1.33.0
|
go.opentelemetry.io/otel v1.33.0
|
||||||
go.unistack.org/micro/v3 v3.11.22
|
go.unistack.org/micro/v3 v3.11.37
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
github.com/ash3in/uuidv8 v1.2.0 // indirect
|
||||||
github.com/klauspost/compress v1.17.11 // indirect
|
github.com/klauspost/compress v1.17.11 // indirect
|
||||||
|
github.com/kr/pretty v0.3.1 // indirect
|
||||||
|
github.com/matoous/go-nanoid v1.5.1 // indirect
|
||||||
github.com/pierrec/lz4/v4 v4.1.22 // indirect
|
github.com/pierrec/lz4/v4 v4.1.22 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
|
||||||
go.unistack.org/micro-proto/v3 v3.4.1 // indirect
|
go.unistack.org/micro-proto/v3 v3.4.1 // indirect
|
||||||
golang.org/x/crypto v0.31.0 // indirect
|
golang.org/x/crypto v0.31.0 // indirect
|
||||||
golang.org/x/net v0.32.0 // indirect
|
|
||||||
golang.org/x/sys v0.28.0 // indirect
|
golang.org/x/sys v0.28.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241216192217-9240e9c98484 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20241216192217-9240e9c98484 // indirect
|
||||||
google.golang.org/grpc v1.69.2 // indirect
|
google.golang.org/grpc v1.69.2 // indirect
|
||||||
google.golang.org/protobuf v1.36.0 // indirect
|
google.golang.org/protobuf v1.36.1 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
44
go.sum
44
go.sum
@ -1,18 +1,34 @@
|
|||||||
|
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
|
||||||
|
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
||||||
|
github.com/ash3in/uuidv8 v1.2.0 h1:2oogGdtCPwaVtyvPPGin4TfZLtOGE5F+W++E880G6SI=
|
||||||
|
github.com/ash3in/uuidv8 v1.2.0/go.mod h1:BnU0wJBxnzdEKmVg4xckBkD+VZuecTFTUP3M0dWgyY4=
|
||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||||
|
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
||||||
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
||||||
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/matoous/go-nanoid v1.5.1 h1:aCjdvTyO9LLnTIi0fgdXhOPPvOHjpXN6Ik9DaNjIct4=
|
||||||
|
github.com/matoous/go-nanoid v1.5.1/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U=
|
||||||
github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
|
github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
|
||||||
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||||
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/twmb/franz-go v1.18.0 h1:25FjMZfdozBywVX+5xrWC2W+W76i0xykKjTdEeD2ejw=
|
github.com/twmb/franz-go v1.18.0 h1:25FjMZfdozBywVX+5xrWC2W+W76i0xykKjTdEeD2ejw=
|
||||||
github.com/twmb/franz-go v1.18.0/go.mod h1:zXCGy74M0p5FbXsLeASdyvfLFsBvTubVqctIaa5wQ+I=
|
github.com/twmb/franz-go v1.18.0/go.mod h1:zXCGy74M0p5FbXsLeASdyvfLFsBvTubVqctIaa5wQ+I=
|
||||||
github.com/twmb/franz-go/pkg/kadm v1.14.0 h1:nAn1co1lXzJQocpzyIyOFOjUBf4WHWs5/fTprXy2IZs=
|
github.com/twmb/franz-go/pkg/kadm v1.14.0 h1:nAn1co1lXzJQocpzyIyOFOjUBf4WHWs5/fTprXy2IZs=
|
||||||
@ -23,26 +39,24 @@ go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw=
|
|||||||
go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I=
|
go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I=
|
||||||
go.unistack.org/micro-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqtEa9Q=
|
go.unistack.org/micro-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqtEa9Q=
|
||||||
go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo=
|
go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo=
|
||||||
go.unistack.org/micro/v3 v3.11.0 h1:usQ+8wQuOWpQd4+DGhFXSgZ+e+wOBjuT3W5GJZ02bSs=
|
go.unistack.org/micro/v3 v3.11.37 h1:ZcpnXAYEMcAwmnVb5b7o8/PylGnILxXMHaUlRrPmRI0=
|
||||||
go.unistack.org/micro/v3 v3.11.0/go.mod h1:YzMldzHN9Ei+zy5t/Psu7RUWDZwUfrNYiStSQtTz90g=
|
go.unistack.org/micro/v3 v3.11.37/go.mod h1:POGU5hstnAT9LH70m8FalyQSNi2GfIew71K75JenIZk=
|
||||||
go.unistack.org/micro/v3 v3.11.22 h1:VPtp/+rp/baKlNb6WVlx4ZzufYuwHrfABoftnDi1uek=
|
|
||||||
go.unistack.org/micro/v3 v3.11.22/go.mod h1:TjF2+KJ2RG+IB4d0wnXtaF5KgqwAqy/AMh+w9gDpRHg=
|
|
||||||
golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY=
|
|
||||||
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
|
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
|
||||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
||||||
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
|
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
|
||||||
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
|
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
||||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 h1:8ZmaLZE4XWrtU3MyClkYqqtl6Oegr3235h7jxsDyqCY=
|
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241216192217-9240e9c98484 h1:Z7FRVJPSMaHQxD0uXU8WdgFh8PseLM8Q8NzhnpMrBhQ=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20241216192217-9240e9c98484 h1:Z7FRVJPSMaHQxD0uXU8WdgFh8PseLM8Q8NzhnpMrBhQ=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241216192217-9240e9c98484/go.mod h1:lcTa1sDdWEIHMWlITnIczmw5w60CF9ffkb8Z+DVmmjA=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20241216192217-9240e9c98484/go.mod h1:lcTa1sDdWEIHMWlITnIczmw5w60CF9ffkb8Z+DVmmjA=
|
||||||
google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0=
|
|
||||||
google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
|
google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
|
||||||
google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
|
google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
|
||||||
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
|
||||||
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
25
kgo.go
25
kgo.go
@ -5,8 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"net/http"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@ -29,7 +28,6 @@ var ErrLostMessage = errors.New("message not marked for offsets commit and will
|
|||||||
|
|
||||||
var DefaultRetryBackoffFn = func() func(int) time.Duration {
|
var DefaultRetryBackoffFn = func() func(int) time.Duration {
|
||||||
var rngMu sync.Mutex
|
var rngMu sync.Mutex
|
||||||
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
||||||
return func(fails int) time.Duration {
|
return func(fails int) time.Duration {
|
||||||
const (
|
const (
|
||||||
min = 100 * time.Millisecond
|
min = 100 * time.Millisecond
|
||||||
@ -45,7 +43,7 @@ var DefaultRetryBackoffFn = func() func(int) time.Duration {
|
|||||||
backoff := min * time.Duration(1<<(fails-1))
|
backoff := min * time.Duration(1<<(fails-1))
|
||||||
|
|
||||||
rngMu.Lock()
|
rngMu.Lock()
|
||||||
jitter := 0.8 + 0.4*rng.Float64()
|
jitter := 0.8 + 0.4*rand.Float64()
|
||||||
rngMu.Unlock()
|
rngMu.Unlock()
|
||||||
|
|
||||||
backoff = time.Duration(float64(backoff) * jitter)
|
backoff = time.Duration(float64(backoff) * jitter)
|
||||||
@ -58,13 +56,16 @@ var DefaultRetryBackoffFn = func() func(int) time.Duration {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
type Broker struct {
|
type Broker struct {
|
||||||
init bool
|
|
||||||
c *kgo.Client
|
c *kgo.Client
|
||||||
kopts []kgo.Opt
|
|
||||||
connected *atomic.Uint32
|
connected *atomic.Uint32
|
||||||
sync.RWMutex
|
|
||||||
opts broker.Options
|
kopts []kgo.Opt
|
||||||
subs []*Subscriber
|
subs []*Subscriber
|
||||||
|
|
||||||
|
opts broker.Options
|
||||||
|
|
||||||
|
sync.RWMutex
|
||||||
|
init bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Broker) Live() bool {
|
func (r *Broker) Live() bool {
|
||||||
@ -277,14 +278,14 @@ func (k *Broker) publish(ctx context.Context, msgs []*broker.Message, opts ...br
|
|||||||
|
|
||||||
for _, msg := range msgs {
|
for _, msg := range msgs {
|
||||||
rec := &kgo.Record{Context: ctx, Key: key}
|
rec := &kgo.Record{Context: ctx, Key: key}
|
||||||
|
|
||||||
rec.Topic, _ = msg.Header.Get(metadata.HeaderTopic)
|
rec.Topic, _ = msg.Header.Get(metadata.HeaderTopic)
|
||||||
msg.Header.Del(metadata.HeaderTopic)
|
msg.Header.Del(metadata.HeaderTopic)
|
||||||
|
|
||||||
k.opts.Meter.Counter(semconv.PublishMessageInflight, "endpoint", rec.Topic, "topic", rec.Topic).Inc()
|
k.opts.Meter.Counter(semconv.PublishMessageInflight, "endpoint", rec.Topic, "topic", rec.Topic).Inc()
|
||||||
if options.BodyOnly || k.opts.Codec.String() == "noop" {
|
if options.BodyOnly || k.opts.Codec.String() == "noop" {
|
||||||
rec.Value = msg.Body
|
rec.Value = msg.Body
|
||||||
for k, v := range msg.Header {
|
setHeaders(rec, msg.Header)
|
||||||
rec.Headers = append(rec.Headers, kgo.RecordHeader{Key: http.CanonicalHeaderKey(k), Value: []byte(v)})
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
rec.Value, err = k.opts.Codec.Marshal(msg)
|
rec.Value, err = k.opts.Codec.Marshal(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -350,7 +351,7 @@ func (k *Broker) TopicExists(ctx context.Context, topic string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *Broker) BatchSubscribe(ctx context.Context, topic string, handler broker.BatchHandler, opts ...broker.SubscribeOption) (broker.Subscriber, error) {
|
func (k *Broker) BatchSubscribe(_ context.Context, _ string, _ broker.BatchHandler, _ ...broker.SubscribeOption) (broker.Subscriber, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
meter.go
2
meter.go
@ -61,7 +61,7 @@ const (
|
|||||||
labelTopic = "topic"
|
labelTopic = "topic"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m *hookMeter) OnGroupManageError(err error) {
|
func (m *hookMeter) OnGroupManageError(_ error) {
|
||||||
m.meter.Counter(metricBrokerGroupErrors).Inc()
|
m.meter.Counter(metricBrokerGroupErrors).Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,29 +22,35 @@ type tp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type consumer struct {
|
type consumer struct {
|
||||||
c *kgo.Client
|
|
||||||
topic string
|
topic string
|
||||||
partition int32
|
|
||||||
|
c *kgo.Client
|
||||||
htracer *hookTracer
|
htracer *hookTracer
|
||||||
opts broker.SubscribeOptions
|
|
||||||
kopts broker.Options
|
|
||||||
handler broker.Handler
|
handler broker.Handler
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
recs chan kgo.FetchTopicPartition
|
recs chan kgo.FetchTopicPartition
|
||||||
|
|
||||||
|
kopts broker.Options
|
||||||
|
opts broker.SubscribeOptions
|
||||||
|
|
||||||
|
partition int32
|
||||||
}
|
}
|
||||||
|
|
||||||
type Subscriber struct {
|
type Subscriber struct {
|
||||||
c *kgo.Client
|
|
||||||
topic string
|
|
||||||
htracer *hookTracer
|
|
||||||
opts broker.SubscribeOptions
|
|
||||||
kopts broker.Options
|
|
||||||
handler broker.Handler
|
|
||||||
closed bool
|
|
||||||
done chan struct{}
|
|
||||||
consumers map[tp]*consumer
|
consumers map[tp]*consumer
|
||||||
|
c *kgo.Client
|
||||||
|
htracer *hookTracer
|
||||||
|
topic string
|
||||||
|
|
||||||
|
handler broker.Handler
|
||||||
|
done chan struct{}
|
||||||
|
kopts broker.Options
|
||||||
|
opts broker.SubscribeOptions
|
||||||
|
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
closed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Subscriber) Client() *kgo.Client {
|
func (s *Subscriber) Client() *kgo.Client {
|
||||||
@ -138,8 +144,8 @@ func (s *Subscriber) poll(ctx context.Context) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
fetches.EachPartition(func(p kgo.FetchTopicPartition) {
|
fetches.EachPartition(func(p kgo.FetchTopicPartition) {
|
||||||
tp := tp{p.Topic, p.Partition}
|
nTp := tp{p.Topic, p.Partition}
|
||||||
s.consumers[tp].recs <- p
|
s.consumers[nTp].recs <- p
|
||||||
})
|
})
|
||||||
s.c.AllowRebalance()
|
s.c.AllowRebalance()
|
||||||
}
|
}
|
||||||
@ -152,9 +158,9 @@ func (s *Subscriber) killConsumers(ctx context.Context, lost map[string][]int32)
|
|||||||
|
|
||||||
for topic, partitions := range lost {
|
for topic, partitions := range lost {
|
||||||
for _, partition := range partitions {
|
for _, partition := range partitions {
|
||||||
tp := tp{topic, partition}
|
nTp := tp{topic, partition}
|
||||||
pc := s.consumers[tp]
|
pc := s.consumers[nTp]
|
||||||
delete(s.consumers, tp)
|
delete(s.consumers, nTp)
|
||||||
close(pc.quit)
|
close(pc.quit)
|
||||||
if s.kopts.Logger.V(logger.DebugLevel) {
|
if s.kopts.Logger.V(logger.DebugLevel) {
|
||||||
s.kopts.Logger.Debug(ctx, fmt.Sprintf("[kgo] waiting for work to finish topic %s partition %d", topic, partition))
|
s.kopts.Logger.Debug(ctx, fmt.Sprintf("[kgo] waiting for work to finish topic %s partition %d", topic, partition))
|
||||||
|
@ -11,9 +11,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type hookTracer struct {
|
type hookTracer struct {
|
||||||
|
tracer tracer.Tracer
|
||||||
clientID string
|
clientID string
|
||||||
group string
|
group string
|
||||||
tracer tracer.Tracer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var messagingSystem = semconv.MessagingSystemKey.String("kafka")
|
var messagingSystem = semconv.MessagingSystemKey.String("kafka")
|
||||||
@ -68,7 +68,7 @@ func (m *hookTracer) OnProduceRecordBuffered(r *kgo.Record) {
|
|||||||
r.Context, _ = m.tracer.Start(r.Context, "sdk.broker", opts...)
|
r.Context, _ = m.tracer.Start(r.Context, "sdk.broker", opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
setHeaders(r, omd)
|
setHeaders(r, omd, metadata.HeaderContentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnProduceRecordUnbuffered continues and ends the "publish" span for an
|
// OnProduceRecordUnbuffered continues and ends the "publish" span for an
|
||||||
@ -135,7 +135,7 @@ func (m *hookTracer) OnFetchRecordBuffered(r *kgo.Record) {
|
|||||||
r.Context, _ = m.tracer.Start(r.Context, "sdk.broker", opts...)
|
r.Context, _ = m.tracer.Start(r.Context, "sdk.broker", opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
setHeaders(r, omd)
|
setHeaders(r, omd, metadata.HeaderContentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnFetchRecordUnbuffered continues and ends the "receive" span for an
|
// OnFetchRecordUnbuffered continues and ends the "receive" span for an
|
||||||
|
Loading…
x
Reference in New Issue
Block a user