Skip to content

Commit

Permalink
Merge pull request #56 from ShaPoHun/SASL_SSL
Browse files Browse the repository at this point in the history
support kafka connection type: SASL_SSL
  • Loading branch information
kevwan committed Oct 10, 2023
2 parents c223788 + 418acc8 commit 4a99c09
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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

0 comments on commit 4a99c09

Please sign in to comment.