Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support kafka connection type: SASL_SSL #56

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kq/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type KqConf struct {
Brokers []string
Group string
Topic string
CaFile string `json:",optional"`
Offset string `json:",options=first|last,default=last"`
Conns int `json:",default=1"`
Consumers int `json:",default=8"`
Expand Down
20 changes: 20 additions & 0 deletions kq/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package kq

import (
"context"
"crypto/tls"
"crypto/x509"
"io"
"log"
"os"
"time"

"github.com/segmentio/kafka-go"
Expand Down Expand Up @@ -121,6 +124,23 @@ func newKafkaQueue(c KqConf, handler ConsumeHandler, options queueOptions) queue
},
}
}
if len(c.CaFile) > 0 {
caCert, err := os.ReadFile(c.CaFile)
if err != nil {
log.Fatal(err)
}

caCertPool := x509.NewCertPool()
ok := caCertPool.AppendCertsFromPEM(caCert)
if !ok {
log.Fatal(err)
}

readerConfig.Dialer.TLS = &tls.Config{
RootCAs: caCertPool,
InsecureSkipVerify: true,
}
}
consumer := kafka.NewReader(readerConfig)

return &kafkaQueue{
Expand Down